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 on loop { continue } #7417

Closed
jonas-schievink opened this issue Jul 1, 2021 · 3 comments · Fixed by #7477
Closed

Lint on loop { continue } #7417

jonas-schievink opened this issue Jul 1, 2021 · 3 comments · Fixed by #7477
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jonas-schievink
Copy link
Contributor

What it does

loop { continue } is heavily used in the embedded ecosystem to sidestep an LLVM miscompilation. However, nowadays it results in the same MIR and thus LLVM IR as loop {}, and the miscompilation of loop {} has been fixed, so this is unnecessary.

Categories (optional)

  • Kind: clippy::style probably, since it's just a confusing way to write loop {}

What is the advantage of the recommended code over the original code

Looks clearer

Drawbacks

None.

Linting on macros that expand to continue; should probably be avoided though.

Example

loop { continue; }

Could be written as:

loop {}
@jonas-schievink jonas-schievink added the A-lint Area: New lints label Jul 1, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Jul 2, 2021
@giraffate
Copy link
Contributor

However, nowadays it results in the same MIR and thus LLVM IR as loop {}, and the miscompilation of loop {} has been fixed, so this is unnecessary.

Is there the related PR or discussion? Just wondering.

@jonas-schievink
Copy link
Contributor Author

The PRs fixing this are probably linked from somewhere in rust-lang/rust#28728

@camsteffen
Copy link
Contributor

This can be an enhancement of needless_continue.

@camsteffen camsteffen added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed A-lint Area: New lints labels Jul 2, 2021
bors added a commit that referenced this issue Jul 26, 2021
Enhance needless continue to detect loop {continue;}

Fixes #7417

changelog: Report [`needless_continue`] in `loop { continue; }` case
bors added a commit that referenced this issue Jul 26, 2021
Enhance needless continue to detect loop {continue;}

Fixes #7417

changelog: Report [`needless_continue`] in `loop { continue; }` case
@bors bors closed this as completed in 02d70f3 Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants