summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/empty_loop.rs
blob: 6a8e6b550c13f0395b355c71f56b1e170a768064 (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
40
41
42
43
44
45
46
47
48
// aux-build:proc_macros.rs

#![warn(clippy::empty_loop)]

extern crate proc_macros;
use proc_macros::{external, inline_macros};

fn should_trigger() {
    loop {}
    loop {
        loop {}
    }

    'outer: loop {
        'inner: loop {}
    }
}

#[inline_macros]
fn should_not_trigger() {
    loop {
        panic!("This is fine")
    }
    let ten_millis = std::time::Duration::from_millis(10);
    loop {
        std::thread::sleep(ten_millis)
    }

    #[allow(clippy::never_loop)]
    'outer: loop {
        'inner: loop {
            break 'inner;
        }
        break 'outer;
    }

    // Make sure `allow` works for this lint
    #[allow(clippy::empty_loop)]
    loop {}

    // We don't lint loops inside macros
    inline!(loop {});

    // We don't lint external macros
    external!(loop {});
}

fn main() {}