2 // rustfix-only-machine-applicable
3 // build-pass (FIXME(62277): should be check-pass)
4 // aux-build:fancy-panic.rs
6 extern crate fancy_panic;
8 const C: &str = "abc {}";
9 static S: &str = "{bla}";
11 #[allow(unreachable_code)]
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
19 //~^ WARN panic message is not a string literal
21 //~^ WARN panic message is not a string literal
22 assert!(false, Some(123));
23 //~^ WARN panic message is not a string literal
24 debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
25 panic!(C); //~ WARN panic message is not a string literal
26 panic!(S); //~ WARN panic message is not a string literal
27 std::panic!(123); //~ WARN panic message is not a string literal
28 core::panic!(&*"abc"); //~ WARN panic message is not a string literal
29 panic!(Some(123)); //~ WARN panic message is not a string literal
30 panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
31 panic!(concat!("{", "{")); //~ WARN panic message contains braces
33 fancy_panic::fancy_panic!("test {} 123");
34 //~^ WARN panic message contains an unused formatting placeholder
36 fancy_panic::fancy_panic!(); // OK
37 fancy_panic::fancy_panic!(S); // OK
43 panic!(a!()); //~ WARN panic message is not a string literal
45 panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
46 assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
47 debug_assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
49 panic![123]; //~ WARN panic message is not a string literal
50 panic!{123}; //~ WARN panic message is not a string literal
52 // Check that the lint only triggers for std::panic and core::panic,
53 // not any panic macro:
66 fn a<T: Send + 'static>(v: T) {
67 panic!(v); //~ WARN panic message is not a string literal
68 assert!(false, v); //~ WARN panic message is not a string literal
71 fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
72 panic!(v); //~ WARN panic message is not a string literal
73 assert!(false, v); //~ WARN panic message is not a string literal
76 fn c<T: std::fmt::Display + Send + 'static>(v: T) {
77 panic!(v); //~ WARN panic message is not a string literal
78 assert!(false, v); //~ WARN panic message is not a string literal
81 fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
82 panic!(v); //~ WARN panic message is not a string literal
83 assert!(false, v); //~ WARN panic message is not a string literal