Open
Description
Using the following flags
--force-warn unused_parens
this code:
fn foo() {
let _x = || 'outer: loop {
let inner = 'inner: loop {
let i = Default::default();
if (break 'outer i) {
loop { break 'inner 5i8; };
} else if true {
break 'inner 6;
}
break 7;
};
break inner < 8;
};
}
caused the following diagnostics:
Checking _snippet_0 v0.1.0 (/tmp/icemaker_global_tempdir.IbV1PR0WiGNQ/icemaker_clippyfix_tempdir.vZHbFsvN0OT0/_snippet_0)
warning: unnecessary parentheses around `if` condition
--> src/lib.rs:5:16
|
5 | if (break 'outer i) {
| ^ ^
|
= note: requested on the command line with `--force-warn unused-parens`
help: remove these parentheses
|
5 - if (break 'outer i) {
5 + if break 'outer i {
|
warning: `_snippet_0` (lib) generated 1 warning (run `cargo clippy --fix --lib -p _snippet_0` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
However after applying these diagnostics, the resulting code:
fn foo() {
let _x = || 'outer: loop {
let inner = 'inner: loop {
let i = Default::default();
if break 'outer i {
loop { break 'inner 5i8; };
} else if true {
break 'inner 6;
}
break 7;
};
break inner < 8;
};
}
no longer compiled:
Checking _snippet_0 v0.1.0 (/tmp/icemaker_global_tempdir.IbV1PR0WiGNQ/icemaker_clippyfix_tempdir.vZHbFsvN0OT0/_snippet_0)
error: expected identifier, found keyword `loop`
--> src/lib.rs:6:17
|
5 | if break 'outer i {
| - while parsing this struct
6 | loop { break 'inner 5i8; };
| ^^^^ expected identifier, found keyword
|
help: escape `loop` to use it as an identifier
|
6 | r#loop { break 'inner 5i8; };
| ++
error: this `if` expression is missing a block after the condition
--> src/lib.rs:5:13
|
5 | if break 'outer i {
| ^^
|
help: add a block here
--> src/lib.rs:7:14
|
7 | } else if true {
| ^
error[E0574]: expected struct, variant or union type, found local variable `i`
--> src/lib.rs:5:29
|
5 | if break 'outer i {
| ^ not a struct, variant or union type
For more information about this error, try `rustc --explain E0574`.
error: could not compile `_snippet_0` (lib test) due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `_snippet_0` (lib) due to 3 previous errors
Version:
rustc 1.90.0-nightly (ed2d75978 2025-06-29)
binary: rustc
commit-hash: ed2d759783dc9de134bbb3f01085b1e6dbf539f3
commit-date: 2025-06-29
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7