Skip to content

Commit a1c3eb6

Browse files
committed
Don't always eval arguments inside .expect(), use unwrap_or_else and closure. (clippy::expect_fun_call)
1 parent 3fc5c11 commit a1c3eb6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/librustdoc/docfs.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ impl DocFS {
9090
let sender = self.errors.sender.clone().unwrap();
9191
rayon::spawn(move || match fs::write(&path, &contents) {
9292
Ok(_) => {
93-
sender
94-
.send(None)
95-
.expect(&format!("failed to send error on \"{}\"", path.display()));
93+
sender.send(None).unwrap_or_else(|_| {
94+
panic!("failed to send error on \"{}\"", path.display())
95+
});
9696
}
9797
Err(e) => {
98-
sender
99-
.send(Some(format!("\"{}\": {}", path.display(), e)))
100-
.expect(&format!("failed to send non-error on \"{}\"", path.display()));
98+
sender.send(Some(format!("\"{}\": {}", path.display(), e))).unwrap_or_else(
99+
|_| panic!("failed to send non-error on \"{}\"", path.display()),
100+
);
101101
}
102102
});
103103
Ok(())

src/libtest/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
158158
.filter(|test| test.desc.name.as_slice() == name)
159159
.map(make_owned_test)
160160
.next()
161-
.expect(&format!("couldn't find a test with the provided name '{}'", name));
161+
.unwrap_or_else(|| panic!("couldn't find a test with the provided name '{}'", name));
162162
let TestDescAndFn { desc, testfn } = test;
163163
let testfn = match testfn {
164164
StaticTestFn(f) => f,

0 commit comments

Comments
 (0)