Skip to content

Diagnostic strips leading underscore #121776

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

Closed
joshlf opened this issue Feb 29, 2024 · 3 comments · Fixed by #121792
Closed

Diagnostic strips leading underscore #121776

joshlf opened this issue Feb 29, 2024 · 3 comments · Fixed by #121792
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue

Comments

@joshlf
Copy link
Contributor

joshlf commented Feb 29, 2024

I tried the following code on Rust 1.76.0:

enum _Foo {
    Bar
}

fn main() {
    let _ = Foo::Bar;
}

I got the following error:

error[E0433]: failed to resolve: use of undeclared type `Foo`
 --> src/main.rs:6:13
  |
6 |     let _ = Foo::Bar;
  |             ^^^ use of undeclared type `Foo`
  |
help: an enum with a similar name exists, consider changing it
  |
1 | enum Foo {
  |      ~~~

Note that the suggestion has stripped the leading _ character from the enum's name.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 29, 2024
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 29, 2024
@jieyouxu
Copy link
Member

Can confirm this is still present in nightly.

@GuillaumeGomez
Copy link
Member

Sounds like fun. Taking a look.

@GuillaumeGomez
Copy link
Member

So it is intended this way from what I can see in the source code:

// When the suggested binding change would be from `x` to `_x`, suggest changing the
// original binding definition instead. (#60164)

Improving the wording would be become to clear the confusion though I think.

@jieyouxu jieyouxu added D-confusing Diagnostics: Confusing error or lint that should be reworked. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Feb 29, 2024
@bors bors closed this as completed in 8a74df9 Feb 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 29, 2024
Rollup merge of rust-lang#121792 - GuillaumeGomez:improve-suggestion, r=michaelwoerister

Improve renaming suggestion when item starts with underscore

Fixes rust-lang#121776.

It goes from:

```terminal
error[E0433]: failed to resolve: use of undeclared type `Foo`
 --> src/foo.rs:6:13
  |
6 |     let _ = Foo::Bar;
  |             ^^^ use of undeclared type `Foo`
  |
help: an enum with a similar name exists, consider changing it
  |
1 | enum Foo {
  |      ~~~
```

to:

```terminal
error[E0433]: failed to resolve: use of undeclared type `Foo`
 --> foo.rs:6:13
  |
6 |     let _ = Foo::Bar;
  |             ^^^ use of undeclared type `Foo`
  |
help: an enum with a similar name exists, consider renaming `_Foo` into `Foo`
  |
1 | enum Foo {
  |      ~~~

error: aborting due to 1 previous error
```
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 A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants