Feedback on needless_continue
in Rust 1.86 · Issue #14536 · rust-lang/rust-clippy (original) (raw)
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 match
es 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