Skip to content

Spurious "downstream crates may implement trait ..." #50238

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

Open
glandium opened this issue Apr 25, 2018 · 4 comments
Open

Spurious "downstream crates may implement trait ..." #50238

glandium opened this issue Apr 25, 2018 · 4 comments
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glandium
Copy link
Contributor

Consider the following code, close to the one in #50237:

#![crate_type="lib"]

use std::marker::PhantomData;

trait Foo {
    type Type: Qux<Self>;
}

struct Bar<T>(PhantomData<T>);

trait Qux<T> {}

impl<T: Foo<Type=U>, U: Qux<T>> From<U> for Bar<T> {
    fn from(t: U) -> Self {
        Bar(PhantomData)
    }
}

This fails to build with:

error[E0119]: conflicting implementations of trait `std::convert::From<Bar<_>>` for type `Bar<_>`:
  --> src/lib.rs:13:1
   |
13 | impl<T: Foo<Type=U>, U: Qux<T>> From<U> for Bar<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl<T> std::convert::From<T> for T;
   = note: downstream crates may implement trait `Qux<_>` for type `Bar<_>`

But how can a downstream crate implement Qux<_> for Bar<_>?

@ChayimFriedman2
Copy link
Contributor

Are there any plans to work on this? Or any known workarounds?

@AZMCode
Copy link

AZMCode commented Dec 3, 2021

This would be useful indeed. Any progress?

@Diegovsky
Copy link

Was hit by this today. It makes writing complex functional code even more complex

@carloskiki
Copy link

Giving another nudge to this issue; Is there any chance it will get fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants