Skip to content

Commit 62b19c6

Browse files
committed
Utilize Result::unwrap_err in more places.
1 parent 50909f2 commit 62b19c6

File tree

13 files changed

+22
-22
lines changed

13 files changed

+22
-22
lines changed

src/libcollectionstest/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_from_utf8() {
5252
String::from("ศไทย中华Việt Nam"));
5353

5454
let xs = b"hello\xFF".to_vec();
55-
let err = String::from_utf8(xs).err().unwrap();
55+
let err = String::from_utf8(xs).unwrap_err();
5656
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
5757
}
5858

src/libserialize/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@ mod tests {
39483948
let mut mem_buf = string::String::new();
39493949
let mut encoder = Encoder::new(&mut mem_buf);
39503950
let result = hm.encode(&mut encoder);
3951-
match result.err().unwrap() {
3951+
match result.unwrap_err() {
39523952
EncoderError::BadHashmapKey => (),
39533953
_ => panic!("expected bad hash map key")
39543954
}

src/libstd/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ mod tests {
17721772
let tmpdir = tmpdir();
17731773
let dir = &tmpdir.join("mkdir_error_twice");
17741774
check!(fs::create_dir(dir));
1775-
let e = fs::create_dir(dir).err().unwrap();
1775+
let e = fs::create_dir(dir).unwrap_err();
17761776
assert_eq!(e.kind(), ErrorKind::AlreadyExists);
17771777
}
17781778

src/libstd/io/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ mod tests {
11271127
let mut writer = BufWriter::new(PanicWriter);
11281128
let _ = writer.write(b"hello world");
11291129
let _ = writer.flush();
1130-
}).join().err().unwrap();
1130+
}).join().unwrap_err();
11311131

11321132
assert_eq!(WRITES.load(Ordering::SeqCst), 1);
11331133
}

src/libstd/sync/mpsc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<T> Sender<T> {
535535
///
536536
/// // This send will fail because the receiver is gone
537537
/// drop(rx);
538-
/// assert_eq!(tx.send(1).err().unwrap().0, 1);
538+
/// assert_eq!(tx.send(1).unwrap_err().0, 1);
539539
/// ```
540540
#[stable(feature = "rust1", since = "1.0.0")]
541541
pub fn send(&self, t: T) -> Result<(), SendError<T>> {

src/libterm/terminfo/parm.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ mod test {
594594
assert!(res.is_ok(),
595595
"Op {} failed with 1 stack entry: {}",
596596
cap,
597-
res.err().unwrap());
597+
res.unwrap_err());
598598
}
599599
let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"];
600600
for &cap in caps.iter() {
@@ -610,7 +610,7 @@ mod test {
610610
assert!(res.is_ok(),
611611
"Binop {} failed with 2 stack entries: {}",
612612
cap,
613-
res.err().unwrap());
613+
res.unwrap_err());
614614
}
615615
}
616616

@@ -625,15 +625,15 @@ mod test {
625625
for &(op, bs) in v.iter() {
626626
let s = format!("%{{1}}%{{2}}%{}%d", op);
627627
let res = expand(s.as_bytes(), &[], &mut Variables::new());
628-
assert!(res.is_ok(), res.err().unwrap());
628+
assert!(res.is_ok(), res.unwrap_err());
629629
assert_eq!(res.unwrap(), vec![b'0' + bs[0]]);
630630
let s = format!("%{{1}}%{{1}}%{}%d", op);
631631
let res = expand(s.as_bytes(), &[], &mut Variables::new());
632-
assert!(res.is_ok(), res.err().unwrap());
632+
assert!(res.is_ok(), res.unwrap_err());
633633
assert_eq!(res.unwrap(), vec![b'0' + bs[1]]);
634634
let s = format!("%{{2}}%{{1}}%{}%d", op);
635635
let res = expand(s.as_bytes(), &[], &mut Variables::new());
636-
assert!(res.is_ok(), res.err().unwrap());
636+
assert!(res.is_ok(), res.unwrap_err());
637637
assert_eq!(res.unwrap(), vec![b'0' + bs[2]]);
638638
}
639639
}
@@ -643,13 +643,13 @@ mod test {
643643
let mut vars = Variables::new();
644644
let s = b"\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m";
645645
let res = expand(s, &[Number(1)], &mut vars);
646-
assert!(res.is_ok(), res.err().unwrap());
646+
assert!(res.is_ok(), res.unwrap_err());
647647
assert_eq!(res.unwrap(), "\\E[31m".bytes().collect::<Vec<_>>());
648648
let res = expand(s, &[Number(8)], &mut vars);
649-
assert!(res.is_ok(), res.err().unwrap());
649+
assert!(res.is_ok(), res.unwrap_err());
650650
assert_eq!(res.unwrap(), "\\E[90m".bytes().collect::<Vec<_>>());
651651
let res = expand(s, &[Number(42)], &mut vars);
652-
assert!(res.is_ok(), res.err().unwrap());
652+
assert!(res.is_ok(), res.unwrap_err());
653653
assert_eq!(res.unwrap(), "\\E[38;5;42m".bytes().collect::<Vec<_>>());
654654
}
655655

src/test/run-make/static-unwinding/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
thread::spawn(move|| {
2626
let _a = A;
2727
lib::callback(|| panic!());
28-
}).join().err().unwrap();
28+
}).join().unwrap_err();
2929

3030
unsafe {
3131
assert_eq!(lib::statik, 1);

src/test/run-pass/command-before-exec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn main() {
6262

6363
let output = Command::new(&me).arg("bad").before_exec(|| {
6464
Err(Error::from_raw_os_error(102))
65-
}).output().err().unwrap();
65+
}).output().unwrap_err();
6666
assert_eq!(output.raw_os_error(), Some(102));
6767

6868
let pid = unsafe { libc::getpid() };

src/test/run-pass/no-landing-pads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fn main() {
2727
thread::spawn(move|| -> () {
2828
let _a = A;
2929
panic!();
30-
}).join().err().unwrap();
30+
}).join().unwrap_err();
3131
assert!(unsafe { !HIT });
3232
}

src/test/run-pass/panic-recover-propagate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ fn main() {
2828
panic!("hi there");
2929
});
3030

31-
panic::propagate(result.err().unwrap());
31+
panic::propagate(result.unwrap_err());
3232
}).join();
3333

34-
let msg = *result.err().unwrap().downcast::<&'static str>().unwrap();
34+
let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
3535
assert_eq!("hi there", msg);
3636
assert_eq!(1, A.load(Ordering::SeqCst));
3737
}

src/test/run-pass/sepcomp-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ mod b {
3939
}
4040

4141
fn main() {
42-
thread::spawn(move|| { ::b::g() }).join().err().unwrap();
42+
thread::spawn(move|| { ::b::g() }).join().unwrap_err();
4343
}

src/test/run-pass/terminate-in-initializer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ fn test_ret() { let _x: Box<isize> = return; }
2424

2525
fn test_panic() {
2626
fn f() { let _x: Box<isize> = panic!(); }
27-
thread::spawn(move|| f() ).join().err().unwrap();
27+
thread::spawn(move|| f() ).join().unwrap_err();
2828
}
2929

3030
fn test_panic_indirect() {
3131
fn f() -> ! { panic!(); }
3232
fn g() { let _x: Box<isize> = f(); }
33-
thread::spawn(move|| g() ).join().err().unwrap();
33+
thread::spawn(move|| g() ).join().unwrap_err();
3434
}
3535

3636
pub fn main() {

src/test/run-pass/unit-like-struct-drop-run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ pub fn main() {
3030
let _b = Foo;
3131
}).join();
3232

33-
let s = x.err().unwrap().downcast::<&'static str>().unwrap();
33+
let s = x.unwrap_err().downcast::<&'static str>().unwrap();
3434
assert_eq!(&**s, "This panic should happen.");
3535
}

0 commit comments

Comments
 (0)