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

Confusing error with integer identifers #106552

Closed
Ezrashaw opened this issue Jan 7, 2023 · 2 comments · Fixed by #106591
Closed

Confusing error with integer identifers #106552

Ezrashaw opened this issue Jan 7, 2023 · 2 comments · Fixed by #106591
Assignees
Labels
C-bug Category: This is a bug.

Comments

@Ezrashaw
Copy link
Contributor

Ezrashaw commented Jan 7, 2023

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d53daa961c3b462df261d1e774a9329f

fn main() {
    let 6 = 5;
}

I expected to see an error explaining the limits on identifiers (identifiers can't start with digits).

Instead, I got a pattern-matching error:

error[E0005]: refutable pattern in local binding: `i32::MIN..=5_i32` and `7_i32..=i32::MAX` not covered
 --> src/main.rs:4:5
  |
4 | let 6 = 5;
  |     ^ patterns `i32::MIN..=5_i32` and `7_i32..=i32::MAX` not covered
  |
  = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
  = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
  = note: the matched value is of type `i32`
help: you might want to use `if let` to ignore the variants that aren't matched
  |
4 | if let 6 = 5 { todo!() }
  | ++           ~~~~~~~~~~~

While of course this error is correct, perhaps a note should be added explaining that you can't use a number as an identifier.

Meta

Occurs on latest stable and nightly.

@rustbot claim

@Ezrashaw Ezrashaw added the C-bug Category: This is a bug. label Jan 7, 2023
@ibraheemdev
Copy link
Member

This isn't a bug, 6 is a pattern there. For example, this compiles:

let 6 = 5 else { panic!("6 != 5") };

@Ezrashaw
Copy link
Contributor Author

Ezrashaw commented Jan 8, 2023

Yes, but does a new contributor know that? Typically you would use a if statement here, if we see this then most likely a user has mistyped let _6 = 5; or something to that effect. A non-pattern binding here would be more common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants