- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: link
fn main() {
    x = x = x;
}The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `x` in this scope
 --> src/main.rs:2:5
  |
2 |     x = x = x;
  |     ^
  |
help: you might have meant to introduce a new binding
  |
2 |     let x = x = x;
  |     +++
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `x` in this scope
 --> src/main.rs:2:9
  |
2 |     x = x = x;
  |         ^
  |
help: you might have meant to introduce a new binding
  |
2 |     x = let x = x;
  |         +++
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `x` in this scope
 --> src/main.rs:2:13
  |
2 |     x = x = x;
  |             ^
  |
help: you might have meant to introduce a new binding
  |
2 |     x = x = let x;
  |             +++
For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to 3 previous errors
Ideally the output should first check the RHS, before suggest adding let. It should also avoid suggesting when code is invalid. Thanks.
Something like this should also not suggest adding let: link
fn main() {
    x = i32
}Compiling playground v0.0.1 (/playground)
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `x` in this scope
 --> src/main.rs:2:5
  |
2 |     x = i32
  |     ^
  |
help: you might have meant to introduce a new binding
  |
2 |     let x = i32
  |     +++
error[[E0423]](https://doc.rust-lang.org/nightly/error-index.html#E0423): expected value, found builtin type `i32`
 --> src/main.rs:2:9
  |
2 |     x = i32
  |         ^^^ not a value
  |
help: consider importing one of these items instead
  |
1 | [use fastrand::i32;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |
1 | [use nom::character::complete::i32;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |
1 | [use nom::character::streaming::i32;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |
1 | [use nom::number::complete::i32;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |
    and 1 other candidate
Some errors have detailed explanations: E0423, E0425.
For more information about an error, try `rustc --explain E0423`.
error: could not compile `playground` due to 2 previous errors
cc @chenyukang
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.