From 3df7720ef7367924e13ff7e013d31ae59b2a97b8 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 6 May 2016 19:32:18 -0400 Subject: [PATCH] Utilize `Result::unwrap_err` in more places. --- src/libcollectionstest/string.rs | 2 +- src/libserialize/json.rs | 2 +- src/libstd/fs.rs | 4 ++-- src/libstd/io/buffered.rs | 2 +- src/libstd/sync/mpsc/mod.rs | 2 +- src/libterm/terminfo/parm.rs | 16 ++++++++-------- src/test/run-make/static-unwinding/main.rs | 2 +- src/test/run-pass/command-before-exec.rs | 2 +- src/test/run-pass/no-landing-pads.rs | 2 +- src/test/run-pass/panic-recover-propagate.rs | 4 ++-- src/test/run-pass/sepcomp-unwind.rs | 2 +- src/test/run-pass/terminate-in-initializer.rs | 4 ++-- src/test/run-pass/unit-like-struct-drop-run.rs | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libcollectionstest/string.rs b/src/libcollectionstest/string.rs index d71529023f4f7..c2eafa1b90f12 100644 --- a/src/libcollectionstest/string.rs +++ b/src/libcollectionstest/string.rs @@ -52,7 +52,7 @@ fn test_from_utf8() { String::from("ศไทย中华Việt Nam")); let xs = b"hello\xFF".to_vec(); - let err = String::from_utf8(xs).err().unwrap(); + let err = String::from_utf8(xs).unwrap_err(); assert_eq!(err.into_bytes(), b"hello\xff".to_vec()); } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index a7d723515664d..90b2c6116038c 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -3948,7 +3948,7 @@ mod tests { let mut mem_buf = string::String::new(); let mut encoder = Encoder::new(&mut mem_buf); let result = hm.encode(&mut encoder); - match result.err().unwrap() { + match result.unwrap_err() { EncoderError::BadHashmapKey => (), _ => panic!("expected bad hash map key") } diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 03ebaa59ca562..0bfd7dad31487 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1772,7 +1772,7 @@ mod tests { let tmpdir = tmpdir(); let dir = &tmpdir.join("mkdir_error_twice"); check!(fs::create_dir(dir)); - let e = fs::create_dir(dir).err().unwrap(); + let e = fs::create_dir(dir).unwrap_err(); assert_eq!(e.kind(), ErrorKind::AlreadyExists); } @@ -2415,7 +2415,7 @@ mod tests { #[test] fn read_dir_not_found() { let res = fs::read_dir("/path/that/does/not/exist"); - assert_eq!(res.err().unwrap().kind(), ErrorKind::NotFound); + assert_eq!(res.unwrap_err().kind(), ErrorKind::NotFound); } #[test] diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 632ef3db80451..a92ca95f4ee7e 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1127,7 +1127,7 @@ mod tests { let mut writer = BufWriter::new(PanicWriter); let _ = writer.write(b"hello world"); let _ = writer.flush(); - }).join().err().unwrap(); + }).join().unwrap_err(); assert_eq!(WRITES.load(Ordering::SeqCst), 1); } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index dbcc2bc95bc21..63b659d8db3b7 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -535,7 +535,7 @@ impl Sender { /// /// // This send will fail because the receiver is gone /// drop(rx); - /// assert_eq!(tx.send(1).err().unwrap().0, 1); + /// assert_eq!(tx.send(1).unwrap_err().0, 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn send(&self, t: T) -> Result<(), SendError> { diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 60b5dffac59ad..fbc6bfb6c8d9f 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -594,7 +594,7 @@ mod test { assert!(res.is_ok(), "Op {} failed with 1 stack entry: {}", cap, - res.err().unwrap()); + res.unwrap_err()); } let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"]; for &cap in caps.iter() { @@ -610,7 +610,7 @@ mod test { assert!(res.is_ok(), "Binop {} failed with 2 stack entries: {}", cap, - res.err().unwrap()); + res.unwrap_err()); } } @@ -625,15 +625,15 @@ mod test { for &(op, bs) in v.iter() { let s = format!("%{{1}}%{{2}}%{}%d", op); let res = expand(s.as_bytes(), &[], &mut Variables::new()); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), vec![b'0' + bs[0]]); let s = format!("%{{1}}%{{1}}%{}%d", op); let res = expand(s.as_bytes(), &[], &mut Variables::new()); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), vec![b'0' + bs[1]]); let s = format!("%{{2}}%{{1}}%{}%d", op); let res = expand(s.as_bytes(), &[], &mut Variables::new()); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), vec![b'0' + bs[2]]); } } @@ -643,13 +643,13 @@ mod test { let mut vars = Variables::new(); let s = b"\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m"; let res = expand(s, &[Number(1)], &mut vars); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), "\\E[31m".bytes().collect::>()); let res = expand(s, &[Number(8)], &mut vars); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), "\\E[90m".bytes().collect::>()); let res = expand(s, &[Number(42)], &mut vars); - assert!(res.is_ok(), res.err().unwrap()); + assert!(res.is_ok(), res.unwrap_err()); assert_eq!(res.unwrap(), "\\E[38;5;42m".bytes().collect::>()); } diff --git a/src/test/run-make/static-unwinding/main.rs b/src/test/run-make/static-unwinding/main.rs index ba4860be91d66..1cd785334f63a 100644 --- a/src/test/run-make/static-unwinding/main.rs +++ b/src/test/run-make/static-unwinding/main.rs @@ -25,7 +25,7 @@ fn main() { thread::spawn(move|| { let _a = A; lib::callback(|| panic!()); - }).join().err().unwrap(); + }).join().unwrap_err(); unsafe { assert_eq!(lib::statik, 1); diff --git a/src/test/run-pass/command-before-exec.rs b/src/test/run-pass/command-before-exec.rs index 16560637b6926..72f952fb6c0df 100644 --- a/src/test/run-pass/command-before-exec.rs +++ b/src/test/run-pass/command-before-exec.rs @@ -62,7 +62,7 @@ fn main() { let output = Command::new(&me).arg("bad").before_exec(|| { Err(Error::from_raw_os_error(102)) - }).output().err().unwrap(); + }).output().unwrap_err(); assert_eq!(output.raw_os_error(), Some(102)); let pid = unsafe { libc::getpid() }; diff --git a/src/test/run-pass/no-landing-pads.rs b/src/test/run-pass/no-landing-pads.rs index 8445bccf13493..e718046ebbcd7 100644 --- a/src/test/run-pass/no-landing-pads.rs +++ b/src/test/run-pass/no-landing-pads.rs @@ -27,6 +27,6 @@ fn main() { thread::spawn(move|| -> () { let _a = A; panic!(); - }).join().err().unwrap(); + }).join().unwrap_err(); assert!(unsafe { !HIT }); } diff --git a/src/test/run-pass/panic-recover-propagate.rs b/src/test/run-pass/panic-recover-propagate.rs index d420ef99863c2..2c87c6b92686c 100644 --- a/src/test/run-pass/panic-recover-propagate.rs +++ b/src/test/run-pass/panic-recover-propagate.rs @@ -28,10 +28,10 @@ fn main() { panic!("hi there"); }); - panic::propagate(result.err().unwrap()); + panic::propagate(result.unwrap_err()); }).join(); - let msg = *result.err().unwrap().downcast::<&'static str>().unwrap(); + let msg = *result.unwrap_err().downcast::<&'static str>().unwrap(); assert_eq!("hi there", msg); assert_eq!(1, A.load(Ordering::SeqCst)); } diff --git a/src/test/run-pass/sepcomp-unwind.rs b/src/test/run-pass/sepcomp-unwind.rs index 96e9c1ed2ccf9..3a93845a0620a 100644 --- a/src/test/run-pass/sepcomp-unwind.rs +++ b/src/test/run-pass/sepcomp-unwind.rs @@ -39,5 +39,5 @@ mod b { } fn main() { - thread::spawn(move|| { ::b::g() }).join().err().unwrap(); + thread::spawn(move|| { ::b::g() }).join().unwrap_err(); } diff --git a/src/test/run-pass/terminate-in-initializer.rs b/src/test/run-pass/terminate-in-initializer.rs index 2875f73fc6cfa..c9133bae85408 100644 --- a/src/test/run-pass/terminate-in-initializer.rs +++ b/src/test/run-pass/terminate-in-initializer.rs @@ -24,13 +24,13 @@ fn test_ret() { let _x: Box = return; } fn test_panic() { fn f() { let _x: Box = panic!(); } - thread::spawn(move|| f() ).join().err().unwrap(); + thread::spawn(move|| f() ).join().unwrap_err(); } fn test_panic_indirect() { fn f() -> ! { panic!(); } fn g() { let _x: Box = f(); } - thread::spawn(move|| g() ).join().err().unwrap(); + thread::spawn(move|| g() ).join().unwrap_err(); } pub fn main() { diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index eaee3505a67ca..ec37be9420db7 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -30,6 +30,6 @@ pub fn main() { let _b = Foo; }).join(); - let s = x.err().unwrap().downcast::<&'static str>().unwrap(); + let s = x.unwrap_err().downcast::<&'static str>().unwrap(); assert_eq!(&**s, "This panic should happen."); }