E4135#
Inconsistent impl of trait: implementations have different self types or
constraints.
When implementing different methods of a trait for the same type, all implementations must agree on the receiver type and type-parameter constraints. If two implementations use different constraints, it is unclear whether a type that satisfies both constraints has a complete and coherent implementation.
Erroneous example#
pub(open) trait I {
f(Self) -> Unit
g(Self) -> Unit
}
pub(all) struct P[X](X)
impl[X : Show] I for P[X] with f(_self) {}
impl[X] I for P[X] with g(_self) {}
Suggestion#
One way to resolve this issue is to make the implementations use the same constraints:
pub(open) trait I {
f(Self) -> Unit
g(Self) -> Unit
}
pub(all) struct P[X](X)
impl[X] I for P[X] with f(_self) {}
impl[X] I for P[X] with g(_self) {}
pub fn use_i(p : P[Int]) -> Unit {
p.f()
p.g()
}
If you want implementations for both constraints, create a new trait that combines the constraints, and manually implement that trait for each type that should satisfy it.