about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-02-03 10:55:33 +0100
committerMara Bos <m-ou.se@m-ou.se>2021-02-03 23:15:51 +0100
commit0870c154b63319df131de822d85dcebcbba080af (patch)
treee1559edeb2e71261e42184c7e81aea3c8e443b99
parent3f3eb89547522be44308c66c5152c65e1a822bbe (diff)
downloadrust-0870c154b63319df131de822d85dcebcbba080af.tar.gz
rust-0870c154b63319df131de822d85dcebcbba080af.zip
Suggest panic!("{}", ..) instead of panic!(..) clippy::expect_fun_call.
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/mod.rs2
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.fixed10
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.stderr10
3 files changed, 11 insertions, 11 deletions
diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs
index a17c5996293..4ee423b383b 100644
--- a/src/tools/clippy/clippy_lints/src/methods/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs
@@ -2183,7 +2183,7 @@ fn lint_expect_fun_call(
         span_replace_word,
         &format!("use of `{}` followed by a function call", name),
         "try this",
-        format!("unwrap_or_else({} {{ panic!({}) }})", closure_args, arg_root_snippet),
+        format!("unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})", closure_args, arg_root_snippet),
         applicability,
     );
 }
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.fixed b/src/tools/clippy/tests/ui/expect_fun_call.fixed
index f3d8a941a92..a756d1cf506 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/expect_fun_call.fixed
@@ -74,12 +74,12 @@ fn main() {
             "foo"
         }
 
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
 
-        Some("foo").unwrap_or_else(|| { panic!(get_static_str()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
     }
 
     //Issue #3839
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.stderr b/src/tools/clippy/tests/ui/expect_fun_call.stderr
index a492e2df89d..6dc796f5cee 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/expect_fun_call.stderr
@@ -34,31 +34,31 @@ error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:77:21
    |
 LL |         Some("foo").expect(&get_string());
-   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:78:21
    |
 LL |         Some("foo").expect(get_string().as_ref());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:79:21
    |
 LL |         Some("foo").expect(get_string().as_str());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:81:21
    |
 LL |         Some("foo").expect(get_static_str());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
 
 error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:82:21
    |
 LL |         Some("foo").expect(get_non_static_str(&0));
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
 
 error: use of `expect` followed by a function call
   --> $DIR/expect_fun_call.rs:86:16