Skip to content

Commit

Permalink
Rollup merge of rust-lang#33474 - frewsxcv:unwrap-err, r=alexcrichton
Browse files Browse the repository at this point in the history
Utilize `Result::unwrap_err` in more places.

None
  • Loading branch information
Manishearth committed May 9, 2016
2 parents c45d481 + 62b19c6 commit fffaf66
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<T> Sender<T> {
///
/// // 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<T>> {
Expand Down
16 changes: 8 additions & 8 deletions src/libterm/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -610,7 +610,7 @@ mod test {
assert!(res.is_ok(),
"Binop {} failed with 2 stack entries: {}",
cap,
res.err().unwrap());
res.unwrap_err());
}
}

Expand All @@ -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]]);
}
}
Expand All @@ -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::<Vec<_>>());
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::<Vec<_>>());
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::<Vec<_>>());
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/static-unwinding/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/command-before-exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/no-landing-pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fn main() {
thread::spawn(move|| -> () {
let _a = A;
panic!();
}).join().err().unwrap();
}).join().unwrap_err();
assert!(unsafe { !HIT });
}
4 changes: 2 additions & 2 deletions src/test/run-pass/panic-recover-propagate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion src/test/run-pass/sepcomp-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ mod b {
}

fn main() {
thread::spawn(move|| { ::b::g() }).join().err().unwrap();
thread::spawn(move|| { ::b::g() }).join().unwrap_err();
}
4 changes: 2 additions & 2 deletions src/test/run-pass/terminate-in-initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ fn test_ret() { let _x: Box<isize> = return; }

fn test_panic() {
fn f() { let _x: Box<isize> = 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<isize> = f(); }
thread::spawn(move|| g() ).join().err().unwrap();
thread::spawn(move|| g() ).join().unwrap_err();
}

pub fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/unit-like-struct-drop-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

0 comments on commit fffaf66

Please sign in to comment.