-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
When refactoring, I accidentally tried to create an while if let
expression. This caused the parser to give me an error about mismatched brackets. This made it difficult to fix the underlying bug.
Given the following code:
fn main() {
let container = vec![Some(1), Some(2), None];
let mut i = 0;
while if let Some(thing) = container.get(i) {
println!("{:?}", thing);
i += 1;
}
}
The current output is:
error: expected `{`, found `}`
--> src/main.rs:9:1
|
9 | }
| ^ expected `{`
Ideally, the output should indicate that either the if
or while
should be deleted.
p.s. it turns out that the let
is not actually necessary to trigger the same error message:
fn main() {
let container = vec![Some(1), Some(2), None];
let mut i = 0;
while if let Some(thing) = container.get(i) {
println!("{:?}", thing);
i += 1;
}
}
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.