rust-clippy/tests/ui/empty_loop.rs

52 lines
928 B
Rust
Raw Normal View History

//@aux-build:proc_macros.rs
2019-05-12 10:10:23 +00:00
#![warn(clippy::empty_loop)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
2019-05-12 10:10:23 +00:00
fn should_trigger() {
loop {}
#[allow(clippy::never_loop)]
2019-05-12 10:10:23 +00:00
loop {
loop {}
}
#[allow(clippy::never_loop)]
2019-05-12 10:10:23 +00:00
'outer: loop {
'inner: loop {}
}
}
#[inline_macros]
2019-05-12 10:10:23 +00:00
fn should_not_trigger() {
#[allow(clippy::never_loop)]
2019-05-12 10:10:23 +00:00
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 {});
2019-05-12 10:10:23 +00:00
// We don't lint external macros
external!(loop {});
2019-05-12 10:10:23 +00:00
}
fn main() {}