-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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 ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Description
Hello.
The following code gives an error message that could be improved:
fn main() {
let n = 1;
if 5 == {
println!("five");
}
}
It gives the following error:
src/main.rs:6:1: 6:2 error: expected `{`, found `}`
src/main.rs:6 }
^
src/main.rs:6:1: 6:2 help: place this code inside a block
This is because the compiler sees the right operand as a block expression, and is looking for the condition body, something like:
fn main() {
let n = 1;
if 5 == {
println!("five");
5
} {
println!("Five");
}
}
while we most probably mean to write something like:
fn main() {
let n = 1;
if 5 == n {
println!("five");
}
}
So, it would be nice to improve this error message.
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 ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics