Skip to content

Duplicated diagnostics when import is ambiguous  #105177

@chenyukang

Description

@chenyukang
Member

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#)
   |     ^

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 2, 2022
lyming2007

lyming2007 commented on Dec 2, 2022

@lyming2007

@rustbot claim

added a commit that references this issue on Dec 19, 2022
bd12d15
added 2 commits that reference this issue on Dec 22, 2022
50c473b
2cace6a
added a commit that references this issue on Dec 27, 2022
b07c112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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

    Participants

    @chenyukang@lyming2007

    Issue actions

      Duplicated diagnostics when import is ambiguous · Issue #105177 · rust-lang/rust