forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#87982 - m-ou-se:non-fmt-panic-assert-str, r=c…
…jgillot Add automatic migration for assert!(.., string). Fixes part of rust-lang#87313.
- Loading branch information
Showing
4 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// run-rustfix | ||
// rustfix-only-machine-applicable | ||
// build-pass (FIXME(62277): should be check-pass) | ||
// aux-build:fancy-panic.rs | ||
|
||
extern crate fancy_panic; | ||
|
||
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 | ||
assert!(false, "{}", S); | ||
//~^ WARN panic message is not a string literal | ||
debug_assert!(false, "{}", "{{}} bla"); //~ WARN panic message contains braces | ||
panic!("{}", C); //~ WARN panic message is not a string literal | ||
panic!("{}", S); //~ WARN panic message is not a string literal | ||
std::panic::panic_any(123); //~ WARN panic message is not a string literal | ||
core::panic!("{}", &*"abc"); //~ WARN panic message is not a string literal | ||
panic!("{}", concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder | ||
panic!("{}", concat!("{", "{")); //~ WARN panic message contains braces | ||
|
||
fancy_panic::fancy_panic!("test {} 123"); | ||
//~^ WARN panic message contains an unused formatting placeholder | ||
|
||
fancy_panic::fancy_panic!(); // OK | ||
fancy_panic::fancy_panic!(S); // OK | ||
|
||
macro_rules! a { | ||
() => { 123 }; | ||
} | ||
|
||
std::panic::panic_any(a!()); //~ WARN panic message is not a string literal | ||
|
||
panic!("{}", 1); //~ WARN panic message is not a string literal | ||
assert!(false, "{}", 1); //~ WARN panic message is not a string literal | ||
debug_assert!(false, "{}", 1); //~ WARN panic message is not a string literal | ||
|
||
std::panic::panic_any(123); //~ WARN panic message is not a string literal | ||
std::panic::panic_any(123); //~ WARN panic message is not a string literal | ||
|
||
// Check that the lint only triggers for std::panic and core::panic, | ||
// not any panic macro: | ||
macro_rules! panic { | ||
($e:expr) => (); | ||
} | ||
panic!("{}"); // OK | ||
panic!(S); // OK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters