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

Duplicate 'upstream crates may add a new impl of trait' notes on inter-crate ambiguous impl of traits #99092

Closed
rhysd opened this issue Jul 9, 2022 · 4 comments · Fixed by #99095
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

@rhysd
Copy link
Contributor

rhysd commented Jul 9, 2022

Given the following code:

struct S;

impl From<()> for S {
    fn from(x: ()) -> Self {
        S
    }
}

impl<I> From<I> for S
where
    I: Iterator<Item = ()>,
{
    fn from(x: I) -> Self {
        S
    }
}

fn main() {}

The current output is:

error[E0119]: conflicting implementations of trait `std::convert::From<()>` for type `S`
  --> foo.rs:9:1
   |
3  |   impl From<()> for S {
   |   ------------------- first implementation here
...
9  | / impl<I> From<I> for S
10 | | where
11 | |     I: Iterator<Item = ()>,
12 | | {
...  |
15 | |     }
16 | | }
   | |_^ conflicting implementation for `S`
   |
   = note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `()` in future versions
   = note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `()` in future versions

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.

Ideally the output should look like:

error[E0119]: conflicting implementations of trait `std::convert::From<()>` for type `S`
  --> foo.rs:9:1
   |
3  |   impl From<()> for S {
   |   ------------------- first implementation here
...
9  | / impl<I> From<I> for S
10 | | where
11 | |     I: Iterator<Item = ()>,
12 | | {
...  |
15 | |     }
16 | | }
   | |_^ conflicting implementation for `S`
   |
   = note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `()` in future versions

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
@rhysd rhysd 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 Jul 9, 2022
@rhysd
Copy link
Contributor Author

rhysd commented Jul 9, 2022

I'll make a PR for fixing this.

@compiler-errors
Copy link
Member

compiler-errors commented Jul 9, 2022

Haha, I was already working on one before I saw that message below, but I'll throw away my changes.

@rhysd, I recommend using a FxIndexSet to track the inter-crate ambiguity causes. That's what I was gonna try.

@rhysd
Copy link
Contributor Author

rhysd commented Jul 9, 2022

@compiler-errors Ah, I'm sorry for interrupting your work... I was thinking to remove duplicates from notes after making messages as String. But your approach would be better. I'll try it.

@compiler-errors
Copy link
Member

No you did not interrupt, I just didn't see your comment saying that you were interested in doing the change yourself. Thanks for contributing.

rhysd added a commit to rhysd/rust that referenced this issue Jul 10, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 10, 2022
Remove duplicate notes from error on inter-crate ambiguous impl of traits

Fixes rust-lang#99092
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 10, 2022
Remove duplicate notes from error on inter-crate ambiguous impl of traits

Fixes rust-lang#99092
@bors bors closed this as completed in d5aed20 Jul 11, 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 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