#Trait impl conflict weirdness

3 messages · Page 1 of 1 (latest)

coarse scarab
#

It's late so it's entirely possible I'm missing something very obvious, but what is going on with this trait impl conflict error?

trait Trait {
    type Assoc;
}

struct TraitWrapper<T>(T);
struct TraitWrapperAssoc<T: Trait>(T::Assoc);

impl<T: Trait> Trait for TraitWrapper<T> {
    type Assoc = TraitWrapperAssoc<T>;
}

impl<T: Trait> From<T::Assoc> for TraitWrapperAssoc<T> {
    fn from(value: T::Assoc) -> TraitWrapperAssoc<T> {
        TraitWrapperAssoc(value)
    }
}


error[E0119]: conflicting implementations of trait `From<TraitWrapperAssoc<_>>` for type `TraitWrapperAssoc<_>`
  --> src/lib.rs:12:1
   |
12 | impl<T: Trait> From<T::Assoc> for TraitWrapperAssoc<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl<T> From<T> for T;

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

TraitWrapperAssoc<T> is not the same type as T::Assoc, right? So why would the from impl conflict with the blanket impl?

prisma verge
#

To rustc T::Assoc could be TraitWrapperAssoc<T>

#

You haven't and can't say it isn't