1
Fork 0

Add test for the panic_fmt lint.

This commit is contained in:
Mara Bos 2020-10-18 22:52:36 +02:00
parent 3beb2e95a9
commit 451c9864c4
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,9 @@
// build-pass (FIXME(62277): should be check-pass)
#[allow(unreachable_code)]
fn main() {
panic!("here's a brace: {"); //~ WARN Panic message contains a brace
std::panic!("another one: }"); //~ WARN Panic message contains a brace
core::panic!("Hello { { {"); //~ WARN Panic message contains a brace
assert!(false, "} } }..."); //~ WARN Panic message contains a brace
}

View file

@ -0,0 +1,51 @@
warning: Panic message contains a brace
--> $DIR/panic-brace.rs:5:5
|
LL | panic!("here's a brace: {");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(panic_fmt)]` on by default
= note: This message is not used as a format string, but will be in a future Rust version
help: add a "{}" format string to use the message literally
|
LL | panic!("{}", "here's a brace: {");
| ^^^^^
warning: Panic message contains a brace
--> $DIR/panic-brace.rs:6:5
|
LL | std::panic!("another one: }");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: This message is not used as a format string, but will be in a future Rust version
help: add a "{}" format string to use the message literally
|
LL | std::panic!("{}", "another one: }");
| ^^^^^
warning: Panic message contains a brace
--> $DIR/panic-brace.rs:7:5
|
LL | core::panic!("Hello { { {");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: This message is not used as a format string, but will be in a future Rust version
help: add a "{}" format string to use the message literally
|
LL | core::panic!("{}", "Hello { { {");
| ^^^^^
warning: Panic message contains a brace
--> $DIR/panic-brace.rs:8:5
|
LL | assert!(false, "} } }...");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: This message is not used as a format string, but will be in a future Rust version
help: add a "{}" format string to use the message literally
|
LL | assert!(false, "{}", "} } }...");
| ^^^^^
warning: 4 warnings emitted