Skip to content

Commit 0870c15

Browse files
committed
Suggest panic!("{}", ..) instead of panic!(..) clippy::expect_fun_call.
1 parent 3f3eb89 commit 0870c15

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Diff for: src/tools/clippy/clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ fn lint_expect_fun_call(
21832183
span_replace_word,
21842184
&format!("use of `{}` followed by a function call", name),
21852185
"try this",
2186-
format!("unwrap_or_else({} {{ panic!({}) }})", closure_args, arg_root_snippet),
2186+
format!("unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})", closure_args, arg_root_snippet),
21872187
applicability,
21882188
);
21892189
}

Diff for: src/tools/clippy/tests/ui/expect_fun_call.fixed

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ fn main() {
7474
"foo"
7575
}
7676

77-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
78-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
79-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
77+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
78+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
79+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
8080

81-
Some("foo").unwrap_or_else(|| { panic!(get_static_str()) });
82-
Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) });
81+
Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
82+
Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
8383
}
8484

8585
//Issue #3839

Diff for: src/tools/clippy/tests/ui/expect_fun_call.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@ error: use of `expect` followed by a function call
3434
--> $DIR/expect_fun_call.rs:77:21
3535
|
3636
LL | Some("foo").expect(&get_string());
37-
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
37+
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
3838

3939
error: use of `expect` followed by a function call
4040
--> $DIR/expect_fun_call.rs:78:21
4141
|
4242
LL | Some("foo").expect(get_string().as_ref());
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
4444

4545
error: use of `expect` followed by a function call
4646
--> $DIR/expect_fun_call.rs:79:21
4747
|
4848
LL | Some("foo").expect(get_string().as_str());
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
5050

5151
error: use of `expect` followed by a function call
5252
--> $DIR/expect_fun_call.rs:81:21
5353
|
5454
LL | Some("foo").expect(get_static_str());
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
5656

5757
error: use of `expect` followed by a function call
5858
--> $DIR/expect_fun_call.rs:82:21
5959
|
6060
LL | Some("foo").expect(get_non_static_str(&0));
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })`
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
6262

6363
error: use of `expect` followed by a function call
6464
--> $DIR/expect_fun_call.rs:86:16

0 commit comments

Comments
 (0)