summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/assertions_on_constants.rs
blob: 7bea9563d47d3d1f34b81de73794aea329f10520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![allow(non_fmt_panics, clippy::needless_bool)]

macro_rules! assert_const {
    ($len:expr) => {
        assert!($len > 0);
        debug_assert!($len < 0);
    };
}
fn main() {
    assert!(true);
    assert!(false);
    assert!(true, "true message");
    assert!(false, "false message");

    let msg = "panic message";
    assert!(false, "{}", msg.to_uppercase());

    const B: bool = true;
    assert!(B);

    const C: bool = false;
    assert!(C);
    assert!(C, "C message");

    debug_assert!(true);
    // Don't lint this, since there is no better way for expressing "Only panic in debug mode".
    debug_assert!(false); // #3948
    assert_const!(3);
    assert_const!(-1);

    // Don't lint if based on `cfg!(..)`:
    assert!(cfg!(feature = "hey") || cfg!(not(feature = "asdf")));

    let flag: bool = cfg!(not(feature = "asdf"));
    assert!(flag);

    const CFG_FLAG: &bool = &cfg!(feature = "hey");
    assert!(!CFG_FLAG);
}