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

Duplicated diagnostics when import is ambiguous #105177

Closed
chenyukang opened this issue Dec 2, 2022 · 1 comment · Fixed by #105769
Closed

Duplicated diagnostics when import is ambiguous #105177

chenyukang opened this issue Dec 2, 2022 · 1 comment · Fixed by #105769
Assignees
Labels
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.

Comments

@chenyukang
Copy link
Member

chenyukang commented Dec 2, 2022

Given the following code:

use self::A::*;
use self::B::*;

enum A {
    V
}

enum B {
    V
}

use V;

fn main() {}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0659]](https://doc.rust-lang.org/nightly/error-index.html#E0659): `V` is ambiguous
  --> src/main.rs:12:5
   |
12 | [use V;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^ ambiguous name
   |
   = note: ambiguous because of multiple glob imports of a name in the same module
note: `V` could refer to the variant imported here
  --> src/main.rs:1:5
   |
1  | [use self::A::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate
note: `V` could also refer to the variant imported here
  --> src/main.rs:2:5
   |
2  | [use self::B::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate

error[[E0659]](https://doc.rust-lang.org/nightly/error-index.html#E0659): `V` is ambiguous
  --> src/main.rs:12:5
   |
12 | [use V;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^ ambiguous name
   |
   = note: ambiguous because of multiple glob imports of a name in the same module
note: `V` could refer to the unit variant imported here
  --> src/main.rs:1:5
   |
1  | [use self::A::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate
note: `V` could also refer to the unit variant imported here
  --> src/main.rs:2:5
   |
2  | [use self::B::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate

warning: unused import: `self::B::*`
 --> src/main.rs:2:5
  |
2 | [use self::B::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `V`
  --> src/main.rs:12:5
   |
12 | [use V;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^

For more information about this error, try `rustc --explain E0659`.
warning: `playground` (bin "playground") generated 2 warnings
error: could not compile `playground` due to 2 previous errors; 2 warnings emitted

There are duplicated diagnostics in output, Ideally the output should look like:

error[[E0659]](https://doc.rust-lang.org/nightly/error-index.html#E0659): `V` is ambiguous
  --> src/main.rs:12:5
   |
12 | [use V;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^ ambiguous name
   |
   = note: ambiguous because of multiple glob imports of a name in the same module
note: `V` could refer to the variant imported here
  --> src/main.rs:1:5
   |
1  | [use self::A::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate
note: `V` could also refer to the variant imported here
  --> src/main.rs:2:5
   |
2  | [use self::B::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^^^^^^^^^^
   = help: consider adding an explicit import of `V` to disambiguate


warning: unused import: `self::B::*`
 --> src/main.rs:2:5
  |
2 | [use self::B::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `V`
  --> src/main.rs:12:5
   |
12 | [use V;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)
   |     ^
@chenyukang chenyukang 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 2, 2022
@lyming2007
Copy link

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 22, 2022
add function to tell the identical errors for ambiguity_errors

if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same we call these 2 ambiguity errors identical
prevent identical ambiguity error from pushing into vector of ambiguity_errors this will fix rust-lang#105177
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 22, 2022
add function to tell the identical errors for ambiguity_errors

if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same we call these 2 ambiguity errors identical
prevent identical ambiguity error from pushing into vector of ambiguity_errors this will fix rust-lang#105177
@bors bors closed this as completed in bd12d15 Dec 22, 2022
MaciejWas pushed a commit to MaciejWas/rust that referenced this issue Dec 27, 2022
…s one in ambiguity_errors

if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same
then these 2 ambiguity errors matched
prevent identical ambiguity error from pushing into vector of ambiguity_errors
this will fix rust-lang#105177
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 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.

2 participants