Skip to content

Unhelpful error message with identifiers named box #97810

@rstk

Description

@rstk

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.

Activity

changed the title [-]Unhelpful error message with variables named `box`[/-] [+]Unhelpful error message with identifiers named `box`[/+] on Jun 6, 2022
ChayimFriedman2

ChayimFriedman2 commented on Jun 7, 2022

@ChayimFriedman2
Contributor

@rustbot claim

est31

est31 commented on Jun 7, 2022

@est31
Member

@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.

added a commit that references this issue on Jun 8, 2022
f12a1c2
added a commit that references this issue on Jun 8, 2022
6fb0467
added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-parserArea: The lexing & parsing of Rust source code to an AST
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-papercutDiagnostics: An error or lint that needs small tweaks.
on Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @estebank@est31@ChayimFriedman2@rstk

    Issue actions

      Unhelpful error message with identifiers named `box` · Issue #97810 · rust-lang/rust