Skip to content

Commit 9f97a0b

Browse files
committed
Add test for panic!(format!(..)) lint.
1 parent a428ab1 commit 9f97a0b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/test/ui/non-fmt-panic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ fn main() {
3535

3636
panic!(a!()); //~ WARN panic message is not a string literal
3737

38+
panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
39+
3840
// Check that the lint only triggers for std::panic and core::panic,
3941
// not any panic macro:
4042
macro_rules! panic {

src/test/ui/non-fmt-panic.stderr

+14-1
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,18 @@ help: or use std::panic::panic_any instead
199199
LL | std::panic::panic_any(a!());
200200
| ^^^^^^^^^^^^^^^^^^^^^^
201201

202-
warning: 15 warnings emitted
202+
warning: panic message is not a string literal
203+
--> $DIR/non-fmt-panic.rs:38:12
204+
|
205+
LL | panic!(format!("{}", 1));
206+
| ^^^^^^^^^^^^^^^^
207+
|
208+
= note: this is no longer accepted in Rust 2021
209+
= note: the panic!() macro supports formatting, so there's no need for the format!() macro here
210+
help: remove the `format!(..)` macro call
211+
|
212+
LL | panic!("{}", 1);
213+
| -- --
214+
215+
warning: 16 warnings emitted
203216

0 commit comments

Comments
 (0)