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

Lint: empty_loop lint on no_std #3746

Closed
therealprof opened this issue Feb 6, 2019 · 3 comments · Fixed by #5086
Closed

Lint: empty_loop lint on no_std #3746

therealprof opened this issue Feb 6, 2019 · 3 comments · Fixed by #5086
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@therealprof
Copy link

In embedded (or no_std) scenarios it is very common to use empty loops in diverging functions such as the #[entry] function or panic handlers. Yet when using clippy we always have to work around the empty_loop lint. Is there a way to disable this lint for no_std applications where it does actually make sense to have it?

@phansch phansch added the A-lint Area: New lints label Feb 6, 2019
@oli-obk oli-obk added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Feb 13, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Feb 13, 2019

This can probably be implemented by checking if any of the attributes in tcx.hir().krate_attrs() is no_std

@eddyp
Copy link

eddyp commented Apr 28, 2019

@therealprof Is this related to the fact clippy complains about loop {} in divergent functions, including the panic! handler, like this?

eddy@aptonia:~/usr/src/rust/learn-rust/app $ cargo clippy 
    Checking app v0.1.0 (/home/eddy/usr/src/rust/learn-rust/app)
warning: empty `loop {}` detected. You may want to either use `panic!()` or add 
`std::thread::sleep(..);` to the loop body.
 --> src/main.rs:8:5
  |
8 |     loop {}
  |     ^^^^^^^
  |
  = note: #[warn(clippy::empty_loop)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/
master/index.html#empty_loop

    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
eddy@aptonia:~/usr/src/rust/learn-rust/app $ egrep '(loop \{\}|no_std)' -B 2 src
/main.rs 
#![no_main]
#![no_std]
--
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
    loop {}

@therealprof
Copy link
Author

@eddyp Precisely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants