Skip to content

Unhelpful error message with identifiers named box #97810

Closed

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

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

    @ChayimFriedman2
    Contributor

    @rustbot claim

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

  4. added a commit that references this issue on Jun 8, 2022
    f12a1c2
  5. added a commit that references this issue on Jun 8, 2022
    6fb0467
  6. added
    A-diagnostics
    A-parser
    T-compiler
    D-confusing
    D-papercut
    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-diagnosticsA-parserD-confusingD-papercutT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions