You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This does not compile, because the trait TraitB is not implemented for the type <<Self as TraitA>::AssocType as TraitA>::AssocType [E0277].
However, my reasoning from the above trait definition would be: when a type T implements TraitB then T::AssocType also implements TraitB. By replacing T with T::AssocType::... (n times) in this theorem, we can conclude that T::AssocType::... (n+1 times) implements TraitB, if its predecessor does so. Thus, by induction all T::AssocType::... (n times) should implement TraitB for all n.
Note, that this is not a problem for concrete implementations of TraitB. But abstract default methods cannot be implemented like that and users of TraitB also can't rely on the recursive trait bound.
Is there any way to make the compiler realize this? Or am I wrong?
The text was updated successfully, but these errors were encountered:
This seems inconsistent. Even though the 'home' of the parameter moved between the two examples (Type in TraitB lives in TraitB's type parameter list and AssocType in TraitB's where clause lives in TraitA), I believe they should be treated the same.
Consider the following code:
This does not compile, because the trait
TraitB
is not implemented for the type<<Self as TraitA>::AssocType as TraitA>::AssocType
[E0277].However, my reasoning from the above trait definition would be: when a type
T
implementsTraitB
thenT::AssocType
also implementsTraitB
. By replacingT
withT::AssocType::...
(n times) in this theorem, we can conclude thatT::AssocType::...
(n+1 times) implementsTraitB
, if its predecessor does so. Thus, by induction allT::AssocType::...
(n times) should implementTraitB
for all n.Note, that this is not a problem for concrete implementations of
TraitB
. But abstract default methods cannot be implemented like that and users ofTraitB
also can't rely on the recursive trait bound.Is there any way to make the compiler realize this? Or am I wrong?
The text was updated successfully, but these errors were encountered: