rust-lang / rust-lang/rust-clippy
Feedback on `needless_continue` in Rust 1.86
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
Starting with Rust 1.86.0, Clippy's needless_continue lint complains about the last statement of a loop, including cases like:
while ... {
match ... {
... if ... => {
...
return ...;
}
_ => continue,
}
}
as well as nested matches in a loop.
One solution in the cases we hit in the Linux kernel is changing continue for (), but arguably using continue shows the intent better when it is alone in an arm like that.
In the kernel in particular, I am not sure we want to force people to try to find other ways to write the code either, in cases when that applies.
Moreover, the help text does not really apply in at least some of the new cases the lint has introduced, e.g. in this one cannot simply "drop" the expression:
warning: this `continue` expression is redundant
--> rust/macros/helpers.rs:85:18
|
85 | _ => continue,
| ^^^^^^^^
|
= help: consider dropping the `continue` expression
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
= note: requested on the command line with `-W clippy::needless-continue`
The examples in the documentation do not show a case like this, either, so the second "help" line does not help.
In addition, locally disabling the lint is not possible with expect, since the behavior differs across versions. Using allow would be possible, but, even then, an extra line just for this is a bit too much, especially if there are other ways to satisfy the lint.
We would like to keep parts of this lint enabled in the kernel, since it does catch some issues that seem good to lint about, but others seem a bit too much. So it is likely we will globally disable this one for the moment.
Could perhaps this lint be split into some of its subcases? Some seem useful, and if most projects agree with some of those, then it may be easier to enable by default at some point.
Thanks!
Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the needless_continue lint behavior described in the issue and the example at rust/macros/helpers.rs:85, then read the linked lint documentation and its examples. Done would require an agreed scope for the reported cases, with the lint behavior, help text, and documentation consistently reflecting that decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100