-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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 .
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.