super trait bounds can result in unconstrained regions #136547
Labels
A-associated-items
Area: Associated items (types, constants & functions)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
T: for<'a> Trait<'a>>
currently elaborates toT: for<'a> Super<SAssoc = <T as Trait<'a>>::TAssoc>
. THe projection clause uses'a
in the term without constraining it in the alias. Manually writing such a where-clause results in an error: https://rust.godbolt.org/z/d8G6GvMbeOne can still implement and use
Trait
as long asTAssoc
does not mention'a
. People use such super trait bounds in the wild, as discovered by a crater run in #136303.Supporting unconstrained regions is difficult as it causes normalization of
<T as SUper>::SAssoc
to use a different unconstrained region variable each time. This can prevent us from proving type outlive bounds, as they rely on region equality when applying assumptions:I've discussed this issue with @compiler-errors and believe that we need to keep supporting such code as it's 'reasonable' and forbidding it results in significant crater breakage.
Our current idea is to encode "One can still implement and use
Trait
as long asTAssoc
does not mention'a
" in the type system by adding support for bivariant region parameters on associated types. We would then change'a
to be bivariant in<T as Trait<'a>>::TAssoc
and ignore it when checking outlives bounds. We'd still get unconstrained regions this way, but they should no longer cause issues.The text was updated successfully, but these errors were encountered: