Auto merge of #4085 - phansch:empty_loop_tests, r=matthiaskrgr

Add tests for empty_loop lint

changelog: none

Closes #4072
This commit is contained in:
bors 2019-05-12 13:50:57 +00:00
commit e9b7a7125e
3 changed files with 83 additions and 0 deletions

View 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
View 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() {}

View 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