rust-clippy/tests/ui/empty_loop.rs

48 lines
840 B
Rust

//@aux-build:proc_macros.rs:proc-macro
#![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() {}