Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for empty_loop lint #4085

Merged
merged 1 commit into from May 12, 2019
Merged
Changes from all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

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