2021-08-12 17:15:47 +00:00
|
|
|
// run-rustfix
|
|
|
|
// rustfix-only-machine-applicable
|
2020-10-18 20:52:36 +00:00
|
|
|
// build-pass (FIXME(62277): should be check-pass)
|
2020-10-29 21:21:40 +00:00
|
|
|
// aux-build:fancy-panic.rs
|
|
|
|
|
|
|
|
extern crate fancy_panic;
|
2020-10-18 20:52:36 +00:00
|
|
|
|
2020-10-20 20:59:53 +00:00
|
|
|
const C: &str = "abc {}";
|
|
|
|
static S: &str = "{bla}";
|
|
|
|
|
2020-10-18 20:52:36 +00:00
|
|
|
#[allow(unreachable_code)]
|
|
|
|
fn main() {
|
2020-10-19 19:14:05 +00:00
|
|
|
panic!("here's a brace: {"); //~ WARN panic message contains a brace
|
2022-01-23 13:57:49 +00:00
|
|
|
unreachable!("here's a brace: {"); //~ WARN panic message contains a brace
|
2020-10-19 19:14:05 +00:00
|
|
|
std::panic!("another one: }"); //~ WARN panic message contains a brace
|
|
|
|
core::panic!("Hello {}"); //~ WARN panic message contains an unused formatting placeholder
|
2020-10-20 20:59:53 +00:00
|
|
|
assert!(false, "{:03x} {test} bla");
|
|
|
|
//~^ WARN panic message contains unused formatting placeholders
|
2021-02-01 21:30:09 +00:00
|
|
|
assert!(false, S);
|
|
|
|
//~^ WARN panic message is not a string literal
|
2021-08-16 15:26:08 +00:00
|
|
|
assert!(false, 123);
|
|
|
|
//~^ WARN panic message is not a string literal
|
|
|
|
assert!(false, Some(123));
|
|
|
|
//~^ WARN panic message is not a string literal
|
2020-10-20 20:59:53 +00:00
|
|
|
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
|
2021-02-01 21:30:09 +00:00
|
|
|
panic!(C); //~ WARN panic message is not a string literal
|
|
|
|
panic!(S); //~ WARN panic message is not a string literal
|
2022-01-23 13:57:49 +00:00
|
|
|
unreachable!(S); //~ WARN panic message is not a string literal
|
|
|
|
unreachable!(S); //~ WARN panic message is not a string literal
|
2021-02-01 21:30:09 +00:00
|
|
|
std::panic!(123); //~ WARN panic message is not a string literal
|
|
|
|
core::panic!(&*"abc"); //~ WARN panic message is not a string literal
|
2021-08-16 15:26:08 +00:00
|
|
|
panic!(Some(123)); //~ WARN panic message is not a string literal
|
2020-10-20 20:59:53 +00:00
|
|
|
panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
|
|
|
|
panic!(concat!("{", "{")); //~ WARN panic message contains braces
|
2020-10-24 19:13:04 +00:00
|
|
|
|
2020-10-29 21:21:40 +00:00
|
|
|
fancy_panic::fancy_panic!("test {} 123");
|
|
|
|
//~^ WARN panic message contains an unused formatting placeholder
|
|
|
|
|
2021-08-12 12:33:30 +00:00
|
|
|
fancy_panic::fancy_panic!(); // OK
|
|
|
|
fancy_panic::fancy_panic!(S); // OK
|
2021-02-01 21:30:09 +00:00
|
|
|
|
2021-02-14 17:17:34 +00:00
|
|
|
macro_rules! a {
|
|
|
|
() => { 123 };
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!(a!()); //~ WARN panic message is not a string literal
|
2022-01-23 13:57:49 +00:00
|
|
|
unreachable!(a!()); //~ WARN panic message is not a string literal
|
2021-02-14 17:17:34 +00:00
|
|
|
|
2021-02-14 17:53:10 +00:00
|
|
|
panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
|
2022-01-23 13:57:49 +00:00
|
|
|
unreachable!(format!("{}", 1)); //~ WARN panic message is not a string literal
|
2021-05-07 17:09:15 +00:00
|
|
|
assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
|
|
|
debug_assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
2021-02-14 17:53:10 +00:00
|
|
|
|
2021-02-14 18:44:57 +00:00
|
|
|
panic![123]; //~ WARN panic message is not a string literal
|
|
|
|
panic!{123}; //~ WARN panic message is not a string literal
|
|
|
|
|
2020-10-24 19:13:04 +00:00
|
|
|
// Check that the lint only triggers for std::panic and core::panic,
|
|
|
|
// not any panic macro:
|
|
|
|
macro_rules! panic {
|
|
|
|
($e:expr) => ();
|
|
|
|
}
|
|
|
|
panic!("{}"); // OK
|
2021-02-01 21:30:09 +00:00
|
|
|
panic!(S); // OK
|
2021-08-16 15:33:42 +00:00
|
|
|
|
|
|
|
a(1);
|
|
|
|
b(1);
|
|
|
|
c(1);
|
|
|
|
d(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn a<T: Send + 'static>(v: T) {
|
|
|
|
panic!(v); //~ WARN panic message is not a string literal
|
2021-08-16 15:35:49 +00:00
|
|
|
assert!(false, v); //~ WARN panic message is not a string literal
|
2021-08-16 15:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
|
|
|
|
panic!(v); //~ WARN panic message is not a string literal
|
2021-08-16 15:35:49 +00:00
|
|
|
assert!(false, v); //~ WARN panic message is not a string literal
|
2021-08-16 15:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn c<T: std::fmt::Display + Send + 'static>(v: T) {
|
|
|
|
panic!(v); //~ WARN panic message is not a string literal
|
2021-08-16 15:35:49 +00:00
|
|
|
assert!(false, v); //~ WARN panic message is not a string literal
|
2021-08-16 15:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
|
|
|
|
panic!(v); //~ WARN panic message is not a string literal
|
2021-08-16 15:35:49 +00:00
|
|
|
assert!(false, v); //~ WARN panic message is not a string literal
|
2020-10-18 20:52:36 +00:00
|
|
|
}
|