Improve panic_fmt error messages for invalid format strings too.
This commit is contained in:
parent
6b44662669
commit
190c3ad64e
3 changed files with 66 additions and 16 deletions
|
|
@ -1,10 +1,18 @@
|
|||
// build-pass (FIXME(62277): should be check-pass)
|
||||
|
||||
const C: &str = "abc {}";
|
||||
static S: &str = "{bla}";
|
||||
|
||||
#[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 an unused formatting placeholder
|
||||
assert!(false, "{:03x} {test} bla"); //~ WARN panic message contains unused formatting placeholders
|
||||
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains a brace
|
||||
assert!(false, "{:03x} {test} bla");
|
||||
//~^ WARN panic message contains unused formatting placeholders
|
||||
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
|
||||
panic!(C); // No warning (yet)
|
||||
panic!(S); // No warning (yet)
|
||||
panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
|
||||
panic!(concat!("{", "{")); //~ WARN panic message contains braces
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
warning: panic message contains a brace
|
||||
--> $DIR/panic-brace.rs:5:5
|
||||
--> $DIR/panic-brace.rs:8:29
|
||||
|
|
||||
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
|
||||
|
|
@ -12,10 +12,10 @@ LL | panic!("{}", "here's a brace: {");
|
|||
| ^^^^^
|
||||
|
||||
warning: panic message contains a brace
|
||||
--> $DIR/panic-brace.rs:6:5
|
||||
--> $DIR/panic-brace.rs:9:31
|
||||
|
|
||||
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
|
||||
|
|
@ -24,7 +24,7 @@ LL | std::panic!("{}", "another one: }");
|
|||
| ^^^^^
|
||||
|
||||
warning: panic message contains an unused formatting placeholder
|
||||
--> $DIR/panic-brace.rs:7:25
|
||||
--> $DIR/panic-brace.rs:10:25
|
||||
|
|
||||
LL | core::panic!("Hello {}");
|
||||
| ^^
|
||||
|
|
@ -40,7 +40,7 @@ LL | core::panic!("{}", "Hello {}");
|
|||
| ^^^^^
|
||||
|
||||
warning: panic message contains unused formatting placeholders
|
||||
--> $DIR/panic-brace.rs:8:21
|
||||
--> $DIR/panic-brace.rs:11:21
|
||||
|
|
||||
LL | assert!(false, "{:03x} {test} bla");
|
||||
| ^^^^^^ ^^^^^^
|
||||
|
|
@ -55,11 +55,11 @@ help: or add a "{}" format string to use the message literally
|
|||
LL | assert!(false, "{}", "{:03x} {test} bla");
|
||||
| ^^^^^
|
||||
|
||||
warning: panic message contains a brace
|
||||
--> $DIR/panic-brace.rs:9:5
|
||||
warning: panic message contains braces
|
||||
--> $DIR/panic-brace.rs:13:27
|
||||
|
|
||||
LL | debug_assert!(false, "{{}} bla");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
|
||||
= 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
|
||||
|
|
@ -67,5 +67,33 @@ help: add a "{}" format string to use the message literally
|
|||
LL | debug_assert!(false, "{}", "{{}} bla");
|
||||
| ^^^^^
|
||||
|
||||
warning: 5 warnings emitted
|
||||
warning: panic message contains an unused formatting placeholder
|
||||
--> $DIR/panic-brace.rs:16:12
|
||||
|
|
||||
LL | panic!(concat!("{", "}"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
|
||||
help: add the missing argument(s)
|
||||
|
|
||||
LL | panic!(concat!("{", "}"), ...);
|
||||
| ^^^^^
|
||||
help: or add a "{}" format string to use the message literally
|
||||
|
|
||||
LL | panic!("{}", concat!("{", "}"));
|
||||
| ^^^^^
|
||||
|
||||
warning: panic message contains braces
|
||||
--> $DIR/panic-brace.rs:17:5
|
||||
|
|
||||
LL | panic!(concat!("{", "{"));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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!("{}", concat!("{", "{"));
|
||||
| ^^^^^
|
||||
|
||||
warning: 7 warnings emitted
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue