Skip to content

Recover from accidental usage of let in struct definition #101683

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

struct Struct {
    let x: i32,
}

fn main() {

}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found keyword `let`
 --> src/main.rs:2:5
  |
2 |     let x: i32,
  |     ^^^ expected identifier, found keyword

error: could not compile `playground` due to previous error

Since normal variable declaration are done using a let or other keywords in front and I accidentally made that typo due to muscle memory from creating regular variables. I think the ideal output for such a typo will be to suggest removing the let and having a small note stating that let is not required for struct variable declarations. (Note: the small note can be omitted if not necessary). This may be useful for beginners first getting used to the language's syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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

    No branches or pull requests

    Issue actions