-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
This currently fails to compile:
trait Trait { fn asdf() {} }
trait A {}
trait B {}
impl<T> Trait for T where T: A {}
impl<T> Trait for T where T: B {}
with error:
<anon>:8:1: 8:34 error: conflicting implementations for trait `Trait` [E0119]
<anon>:8 impl<T> Trait for T where T: A {}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:9:1: 9:34 note: note conflicting implementation here
<anon>:9 impl<T> Trait for T where T: B {}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Naturally, this error makes sense. A type can impl both traits A and B. I was hoping that such a check could be deferred, though, thus resolving these 'conflicts' later when something actually asking for Trait pops up. Ex. a type that impls only A would get the blanket impl for A, and if multiple impls apply (e.g. the type impls both A and B) then the compiler errors out.
Some ideas
It was suggested on IRC that one may allow both blanket impls to apply by using UFCS path syntax to disambiguate trait bounds and narrow down the possibly applicable impls to a single one. Ex. a type that impls both A and B could get both blanket impls but be disambiguated when calling via <Type as A>::asdf().
But really I'd be totally cool with only one blanket impl applying to any one type at any time.