Skip to content

Commit 451c986

Browse files
committed
Add test for the panic_fmt lint.
1 parent 3beb2e9 commit 451c986

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/test/ui/panic-brace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass (FIXME(62277): should be check-pass)
2+
3+
#[allow(unreachable_code)]
4+
fn main() {
5+
panic!("here's a brace: {"); //~ WARN Panic message contains a brace
6+
std::panic!("another one: }"); //~ WARN Panic message contains a brace
7+
core::panic!("Hello { { {"); //~ WARN Panic message contains a brace
8+
assert!(false, "} } }..."); //~ WARN Panic message contains a brace
9+
}

src/test/ui/panic-brace.stderr

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
warning: Panic message contains a brace
2+
--> $DIR/panic-brace.rs:5:5
3+
|
4+
LL | panic!("here's a brace: {");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(panic_fmt)]` on by default
8+
= note: This message is not used as a format string, but will be in a future Rust version
9+
help: add a "{}" format string to use the message literally
10+
|
11+
LL | panic!("{}", "here's a brace: {");
12+
| ^^^^^
13+
14+
warning: Panic message contains a brace
15+
--> $DIR/panic-brace.rs:6:5
16+
|
17+
LL | std::panic!("another one: }");
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
= note: This message is not used as a format string, but will be in a future Rust version
21+
help: add a "{}" format string to use the message literally
22+
|
23+
LL | std::panic!("{}", "another one: }");
24+
| ^^^^^
25+
26+
warning: Panic message contains a brace
27+
--> $DIR/panic-brace.rs:7:5
28+
|
29+
LL | core::panic!("Hello { { {");
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= note: This message is not used as a format string, but will be in a future Rust version
33+
help: add a "{}" format string to use the message literally
34+
|
35+
LL | core::panic!("{}", "Hello { { {");
36+
| ^^^^^
37+
38+
warning: Panic message contains a brace
39+
--> $DIR/panic-brace.rs:8:5
40+
|
41+
LL | assert!(false, "} } }...");
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
|
44+
= note: This message is not used as a format string, but will be in a future Rust version
45+
help: add a "{}" format string to use the message literally
46+
|
47+
LL | assert!(false, "{}", "} } }...");
48+
| ^^^^^
49+
50+
warning: 4 warnings emitted
51+

0 commit comments

Comments
 (0)