]> git.lizzy.rs Git - rust.git/blob - src/test/ui/non-fmt-panic.fixed
Rollup merge of #87967 - m-ou-se:non-fmt-panic-detect-fake-spans, r=cjgillot
[rust.git] / src / test / ui / non-fmt-panic.fixed
1 // run-rustfix
2 // rustfix-only-machine-applicable
3 // build-pass (FIXME(62277): should be check-pass)
4 // aux-build:fancy-panic.rs
5
6 extern crate fancy_panic;
7
8 const C: &str = "abc {}";
9 static S: &str = "{bla}";
10
11 #[allow(unreachable_code)]
12 fn main() {
13     panic!("{}", "here's a brace: {"); //~ WARN panic message contains a brace
14     std::panic!("{}", "another one: }"); //~ WARN panic message contains a brace
15     core::panic!("{}", "Hello {}"); //~ WARN panic message contains an unused formatting placeholder
16     assert!(false, "{}", "{:03x} {test} bla");
17     //~^ WARN panic message contains unused formatting placeholders
18     assert!(false, "{}", S);
19     //~^ WARN panic message is not a string literal
20     debug_assert!(false, "{}", "{{}} bla"); //~ WARN panic message contains braces
21     panic!("{}", C); //~ WARN panic message is not a string literal
22     panic!("{}", S); //~ WARN panic message is not a string literal
23     std::panic::panic_any(123); //~ WARN panic message is not a string literal
24     core::panic!("{}", &*"abc"); //~ WARN panic message is not a string literal
25     panic!("{}", concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
26     panic!("{}", concat!("{", "{")); //~ WARN panic message contains braces
27
28     fancy_panic::fancy_panic!("test {} 123");
29     //~^ WARN panic message contains an unused formatting placeholder
30
31     fancy_panic::fancy_panic!(); // OK
32     fancy_panic::fancy_panic!(S); // OK
33
34     macro_rules! a {
35         () => { 123 };
36     }
37
38     std::panic::panic_any(a!()); //~ WARN panic message is not a string literal
39
40     panic!("{}", 1); //~ WARN panic message is not a string literal
41     assert!(false, "{}", 1); //~ WARN panic message is not a string literal
42     debug_assert!(false, "{}", 1); //~ WARN panic message is not a string literal
43
44     std::panic::panic_any(123); //~ WARN panic message is not a string literal
45     std::panic::panic_any(123); //~ WARN panic message is not a string literal
46
47     // Check that the lint only triggers for std::panic and core::panic,
48     // not any panic macro:
49     macro_rules! panic {
50         ($e:expr) => ();
51     }
52     panic!("{}"); // OK
53     panic!(S); // OK
54 }