Add tests for empty_loop lint
This commit is contained in:
parent
3710ec5996
commit
9a24ab8466
9
tests/ui/auxiliary/macro_rules.rs
Normal file
9
tests/ui/auxiliary/macro_rules.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
/// Used to test that certain lints don't trigger in imported external macros
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! foofoo {
|
||||||
|
() => {
|
||||||
|
loop {}
|
||||||
|
};
|
||||||
|
}
|
52
tests/ui/empty_loop.rs
Normal file
52
tests/ui/empty_loop.rs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// aux-build:macro_rules.rs
|
||||||
|
|
||||||
|
#![warn(clippy::empty_loop)]
|
||||||
|
#![allow(clippy::unused_label)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate macro_rules;
|
||||||
|
|
||||||
|
fn should_trigger() {
|
||||||
|
loop {}
|
||||||
|
loop {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
'outer: loop {
|
||||||
|
'inner: loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
macro_rules! foo {
|
||||||
|
() => {
|
||||||
|
loop {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't lint external macros
|
||||||
|
foofoo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
22
tests/ui/empty_loop.stderr
Normal file
22
tests/ui/empty_loop.stderr
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
|
||||||
|
--> $DIR/empty_loop.rs:10:5
|
||||||
|
|
|
||||||
|
LL | loop {}
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::empty-loop` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
|
||||||
|
--> $DIR/empty_loop.rs:12:9
|
||||||
|
|
|
||||||
|
LL | loop {}
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
|
||||||
|
--> $DIR/empty_loop.rs:16:9
|
||||||
|
|
|
||||||
|
LL | 'inner: loop {}
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user