Trait bounds for generic types do not imply themselves when they restrict associated types #109325
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-trait-system
Area: Trait system
T-types
Relevant to the types team, which will review and decide on the PR/issue.
When restricting a generic type parameter to a trait which is a super trait of another trait, and also places trait bounds on an associated type of the other trait.
For example:
gives the error:
However,
T
must be able to implementSupertrait
, since we asserted that it does with the trait boundT: SuperTrait
.In general, I think checking the trait bounds for trait requirements for generics (in a
where
clause, in<T: Trait>
or(arg: impl Trait)
is unnecessary, since if the trait is implemented then it shouldn't matter how, it inherently must satisfy the trait bounds, and if it does not implement the trait, then it cannot be used as that generic type, so nothing breaks.In the example above, the function doesn't do anything at all, so any arbitrary restrictions on
T
should be valid, since they have no effect on the function.The text was updated successfully, but these errors were encountered: