-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-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 Some(msg) = opt_msg() {
dbg!(msg);
}
}
fn opt_msg() -> Option<&'static str> {
Some("hello world")
}Current output
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
--> src/main.rs:2:31
|
2 | let Some(msg) = opt_msg() {
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: could not compile `playground` due to previous errorDesired output
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
--> src/main.rs:2:31
|
2 | let Some(msg) = opt_msg() {
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
note: if you intended to write an `if let`, put an `if` in front of the `let`, like so:
|
2 | if let Some(msg) = opt_msg() {
|
note: if you intended to write a `let else`, add an `else` and its block after the scrutinee, like so:
|
2 | let Some(msg) = opt_msg() else { ... } {
|
error: could not compile `playground` due to previous errorRationale and extra context
Its pretty natural at times to try to flip code from a let to an if let, but the resulting compiler parsing error is not as helpful as it could be.
Other cases
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-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.