Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Slightly improve error message for invalid identifer #104088

Closed
Rageking8 opened this issue Nov 7, 2022 · 3 comments · Fixed by #104309
Closed

Slightly improve error message for invalid identifer #104088

Rageking8 opened this issue Nov 7, 2022 · 3 comments · Fixed by #104309
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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

@Rageking8
Copy link
Contributor

Rageking8 commented Nov 7, 2022

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.

@Rageking8 Rageking8 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2022
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 8, 2022
@chenyukang
Copy link
Member

@rustbot claim

@chenyukang
Copy link
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
Copy link
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?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2022
…ifier-error, r=davidtwco

Slightly improve error message for invalid identifier

fixes rust-lang#104088
@bors bors closed this as completed in 9db8e18 Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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.

3 participants