Rollup merge of #33474 - frewsxcv:unwrap-err, r=alexcrichton
Utilize `Result::unwrap_err` in more places. None
This commit is contained in:
commit
fffaf665f2
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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>> {
|
||||
|
@ -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::<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<_>>());
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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() };
|
||||
|
@ -27,6 +27,6 @@ fn main() {
|
||||
thread::spawn(move|| -> () {
|
||||
let _a = A;
|
||||
panic!();
|
||||
}).join().err().unwrap();
|
||||
}).join().unwrap_err();
|
||||
assert!(unsafe { !HIT });
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -39,5 +39,5 @@ mod b {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
thread::spawn(move|| { ::b::g() }).join().err().unwrap();
|
||||
thread::spawn(move|| { ::b::g() }).join().unwrap_err();
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user