Skip to content

Slightly improve error message for invalid identifer  #104088

Closed
@Rageking8

Description

@Rageking8
Contributor

Given the following code: link

fn main() {
    let 1x = 123;
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: invalid suffix `x` for number literal
 --> src/main.rs:2:9
  |
2 |     let 1x = 123;
  |         ^^ invalid suffix `x`
  |
  = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

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

Ideally the output should inform the user that an identifier cannot start with a digit and not that the proceeding characters is an invalid suffix (since a literal in that place is invalid in the first place). Thanks.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 7, 2022
added
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-papercutDiagnostics: An error or lint that needs small tweaks.
on Nov 8, 2022
chenyukang

chenyukang commented on Nov 9, 2022

@chenyukang
Member

@rustbot claim

chenyukang

chenyukang commented on Nov 12, 2022

@chenyukang
Member

Which one is a more proper?

   --> $DIR/const-match-check.rs:19:26
    |
 LL |     const X: i32 = { let 0 = 0; 0 };
-   |                          ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered
+   |                          ^ identifiers cannot start with a number
+
chenyukang

chenyukang commented on Nov 12, 2022

@chenyukang
Member

And, this actually is a valid code

fn main() {
    let 3 = 1 + (match 1 { n => n }) else {
        return;
    };
}

We only report for identifer starts with digit and also contains some chars which is not digit, and it's not a valid number literal?

added a commit that references this issue on Nov 15, 2022

Rollup merge of rust-lang#104309 - chenyukang:yukang/fix-104088-ident…

769f231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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

    @chenyukang@estebank@Rageking8

    Issue actions

      Slightly improve error message for invalid identifer · Issue #104088 · rust-lang/rust