Skip to content

Unhelpful error message with identifiers named box #97810

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rstk opened this issue Jun 6, 2022 · 2 comments · Fixed by #97857
Closed

Unhelpful error message with identifiers named box #97810

rstk opened this issue Jun 6, 2022 · 2 comments · Fixed by #97857
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rstk
Copy link

rstk commented Jun 6, 2022

The following code, which won't compile because of (edited: #49733) #29641

fn main() {
    let box = Box::new(1);
}

yields an unhelpful error message:

error: expected pattern, found `=`
 --> src/main.rs:2:13
  |
2 |     let box = Box::new(1);
  |             ^ expected pattern

Particularly confusing if your text editor doesn't highlight box! It would be nicer to show some help proposing to rename the variable.

@rstk rstk changed the title Unhelpful error message with variables named box Unhelpful error message with identifiers named box Jun 6, 2022
@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Jun 7, 2022

@rustbot claim

@est31
Copy link
Member

est31 commented Jun 7, 2022

@rstk FTR you linked to the wrong issue, you should have linked to #29641, as it's a box pattern not a box expression in the case of your snippet.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 8, 2022
…, r=compiler-errors

Suggest escaping `box` as identifier

Fixes rust-lang#97810.
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jun 8, 2022
@bors bors closed this as completed in f12a1c2 Jun 9, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants