Closed
Description
Code
fn main() {
let _ = || { while Some(_) = None { } };
}
Current output
error[E0308]: mismatched types
--> src/main.rs:2:24
|
2 | let _ = || { while Some(_) = None { } };
| ^^^^^^^^^^^^^^ expected `bool`, found `()`
For more information about this error, try `rustc --explain E0308`.
Desired output
error[E0308]: mismatched types
--> src/main.rs:2:24
|
2 | let _ = || { while Some(_) = None { } };
| ^^^^^^^^^^^^^^ expected `bool`, found `()`
help: consider adding `let`
|
2 | let _ = || { while let Some(_) = None { } };
| +++
For more information about this error, try `rustc --explain E0308`.
Rationale and extra context
When an assignment is used as the test in a while
statement, the compiler will add a help
message suggesting while let
instead. This message fails to appear when the erroneous while
statement is inside a closure body.
Other cases
No response
Anything else?
This problem was discovered while investigating #113352 .