Skip to content

Poor diagnostic when using = instead of : in let bindings #133713

New issue

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

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

Already on GitHub? # to your account

Closed
oriongonza opened this issue Dec 1, 2024 · 0 comments · Fixed by #136869
Closed

Poor diagnostic when using = instead of : in let bindings #133713

oriongonza opened this issue Dec 1, 2024 · 0 comments · Fixed by #136869
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oriongonza
Copy link
Contributor

oriongonza commented Dec 1, 2024

Code

let last = u64 = 0;
let val = u64;

Current output

error[E0423]: expected value, found builtin type `u64`
  --> src/main.rs:21:24
   |
21 |         let last = u64 = 0;
   |                        ^^^
   |
help: you might have meant to introduce a new binding
   |
21 |         let last = let u64 = 0;
   |                        +++
error[E0423]: expected value, found builtin type `u64`
  --> src/main.rs:21:20
   |
21 |         let last = u64;
   |                    ^^^ not a value

Desired output

error[E0423]: expected value, found builtin type `u64`
  --> src/main.rs:21:24
   |
21 |         let last = u64 = 0;
   |                        ^^^
   |
help: you might have meant to use `:` instead of `=`
   |
21 |         let last:  u64 = 0;
   |                 +
note: type annotations use `:` instead of `=` (https://doc.rust-lang.org/reference/statements.html#expression-statements)
error[E0423]: expected value, found builtin type `u64`
  --> src/main.rs:21:20
   |
21 |         let last = u64;
   |                    ^^^ not a value
help: you might have meant to use `:` instead of `=`
note: type annotations use `:` instead of `=` (https://doc.rust-lang.org/reference/statements.html#expression-statements)

Rationale and extra context

This is a silly mistake to make and also simple to detect and autofix.

Other cases

Rust Version

1.85.0-nightly (4c39aaff6 2024-11-25)

Anything else?

@rustbot label +D-incorrect +D-confusing +A-parser

@oriongonza oriongonza 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 Dec 1, 2024
@rustbot rustbot added A-parser Area: The lexing & parsing of Rust source code to an AST D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Dec 1, 2024
@chenyukang chenyukang self-assigned this Jan 17, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Feb 14, 2025
…inding, r=estebank

Fix diagnostic when using = instead of : in let binding

Fixes rust-lang#133713

r? `@estebank`
@bors bors closed this as completed in d784803 Feb 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 14, 2025
Rollup merge of rust-lang#136869 - chenyukang:yukang-fix-133713-let-binding, r=estebank

Fix diagnostic when using = instead of : in let binding

Fixes rust-lang#133713

r? ``@estebank``
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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