2022-03-31 23:28:59 -05:00
|
|
|
#![allow(non_fmt_panics, clippy::needless_bool)]
|
2021-02-02 13:24:42 -06:00
|
|
|
|
2019-02-05 12:06:08 -06:00
|
|
|
macro_rules! assert_const {
|
|
|
|
($len:expr) => {
|
|
|
|
assert!($len > 0);
|
|
|
|
debug_assert!($len < 0);
|
|
|
|
};
|
|
|
|
}
|
2018-12-25 16:29:03 -06:00
|
|
|
fn main() {
|
|
|
|
assert!(true);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
2018-12-25 16:29:03 -06:00
|
|
|
assert!(false);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(false)` should probably be replaced
|
2019-01-09 12:30:47 -06:00
|
|
|
assert!(true, "true message");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
2019-01-09 12:30:47 -06:00
|
|
|
assert!(false, "false message");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
2019-01-09 12:30:47 -06:00
|
|
|
|
2019-10-07 13:40:05 -05:00
|
|
|
let msg = "panic message";
|
2021-10-23 02:42:52 -05:00
|
|
|
assert!(false, "{}", msg.to_uppercase());
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
2019-10-07 13:40:05 -05:00
|
|
|
|
2019-01-09 12:30:47 -06:00
|
|
|
const B: bool = true;
|
|
|
|
assert!(B);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
2019-01-09 12:30:47 -06:00
|
|
|
|
|
|
|
const C: bool = false;
|
|
|
|
assert!(C);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(false)` should probably be replaced
|
2019-10-05 09:45:02 -05:00
|
|
|
assert!(C, "C message");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
2019-02-05 12:06:08 -06:00
|
|
|
|
|
|
|
debug_assert!(true);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler
|
2019-04-18 04:48:19 -05:00
|
|
|
// Don't lint this, since there is no better way for expressing "Only panic in debug mode".
|
|
|
|
debug_assert!(false); // #3948
|
2019-02-05 12:06:08 -06:00
|
|
|
assert_const!(3);
|
|
|
|
assert_const!(-1);
|
2021-07-01 11:17:38 -05:00
|
|
|
|
2022-03-31 23:28:59 -05:00
|
|
|
// Don't lint if based on `cfg!(..)`:
|
2021-07-01 11:17:38 -05:00
|
|
|
assert!(cfg!(feature = "hey") || cfg!(not(feature = "asdf")));
|
2022-03-31 23:28:59 -05:00
|
|
|
|
|
|
|
let flag: bool = cfg!(not(feature = "asdf"));
|
|
|
|
assert!(flag);
|
|
|
|
|
|
|
|
const CFG_FLAG: &bool = &cfg!(feature = "hey");
|
|
|
|
assert!(!CFG_FLAG);
|
2023-12-15 13:52:38 -06:00
|
|
|
|
|
|
|
const _: () = assert!(true);
|
|
|
|
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
|
|
|
|
|
|
|
// Don't lint if the value is dependent on a defined constant:
|
|
|
|
const N: usize = 1024;
|
|
|
|
const _: () = assert!(N.is_power_of_two());
|
2018-12-25 16:29:03 -06:00
|
|
|
}
|