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

Tighten "introduce new binding" suggestion #104086

Closed
Rageking8 opened this issue Nov 7, 2022 · 2 comments · Fixed by #104186
Closed

Tighten "introduce new binding" suggestion #104086

Rageking8 opened this issue Nov 7, 2022 · 2 comments · Fixed by #104186
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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() {
    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

@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
@compiler-errors
Copy link
Member

I'm not convinced the second example should be something we need to fix, but the first example should be very easy to fix.

@chenyukang
Copy link
Member

@rustbot claim

@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Nov 8, 2022
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 10, 2022
…inding-issue, r=oli-obk

Tighten the 'introduce new binding' suggestion

Fixes rust-lang#104086
@bors bors closed this as completed in 952df48 Nov 10, 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 D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

4 participants