about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2020-03-05 14:08:27 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2020-03-05 16:39:20 +0100
commita1c3eb60433163e341feddb7c1a1cc7f65421764 (patch)
treebf59560530f56084cb7c5cf3cc4dccc7b6d043d5
parent3fc5c118dd328e786c1f389feac259f65409589c (diff)
downloadrust-a1c3eb60433163e341feddb7c1a1cc7f65421764.tar.gz
rust-a1c3eb60433163e341feddb7c1a1cc7f65421764.zip
Don't always eval arguments inside .expect(), use unwrap_or_else and closure. (clippy::expect_fun_call)
-rw-r--r--src/librustdoc/docfs.rs12
-rw-r--r--src/libtest/lib.rs2
2 files changed, 7 insertions, 7 deletions
diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs
index ecc394a2bc9..9c9a00295c3 100644
--- a/src/librustdoc/docfs.rs
+++ b/src/librustdoc/docfs.rs
@@ -90,14 +90,14 @@ impl DocFS {
             let sender = self.errors.sender.clone().unwrap();
             rayon::spawn(move || match fs::write(&path, &contents) {
                 Ok(_) => {
-                    sender
-                        .send(None)
-                        .expect(&format!("failed to send error on \"{}\"", path.display()));
+                    sender.send(None).unwrap_or_else(|_| {
+                        panic!("failed to send error on \"{}\"", path.display())
+                    });
                 }
                 Err(e) => {
-                    sender
-                        .send(Some(format!("\"{}\": {}", path.display(), e)))
-                        .expect(&format!("failed to send non-error on \"{}\"", path.display()));
+                    sender.send(Some(format!("\"{}\": {}", path.display(), e))).unwrap_or_else(
+                        |_| panic!("failed to send non-error on \"{}\"", path.display()),
+                    );
                 }
             });
             Ok(())
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 6bd3399cd17..55f9df9caaf 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -158,7 +158,7 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
             .filter(|test| test.desc.name.as_slice() == name)
             .map(make_owned_test)
             .next()
-            .expect(&format!("couldn't find a test with the provided name '{}'", name));
+            .unwrap_or_else(|| panic!("couldn't find a test with the provided name '{}'", name));
         let TestDescAndFn { desc, testfn } = test;
         let testfn = match testfn {
             StaticTestFn(f) => f,