Skip to content

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

Closed
@oriongonza

Description

@oriongonza

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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

No branches or pull requests

Issue actions