Using GATs with other associated types sometimes claims those types don't satisfy their supertraits #88405
Labels
A-GATs
Area: Generic associated types (GATs)
A-traits
Area: Trait system
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
F-generic_associated_types
`#![feature(generic_associated_types)]` a.k.a. GATs
requires-nightly
This issue requires a nightly compiler in some way.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Using an associated type as an argument to a GAT will sometimes fail with an incorrect
[E0277]
"trait bound is not satisfied" error, when that type is used to constrain an associated type of another trait.Playground link including the other examples in this issue
This code should compile fine. In particular,
Self::GatBounded<Self::AssociatedType>
should be valid becauseSelf::AssociatedType
is constrained to implementSomeTrait
.However, the compilation fails with the following error:
The trait bound
Self::AssociatedType: SomeTrait
is obviously satisfied, so something is wrong here. The suggestedwhere
clause does not fix the error, instead the compiler will suggest you add another one.Adding the same bound again and again
Further observations
Spreading types over several traits causes the same issue
This error occurs even if the first two
type
s,AssociatedType
andGatBounded
, are part of other traits (implemented either bySelf
or some generic type arguments).Error also happens in generic argument
Error affected by other items in trait
The error seems to be affected by the presence and ordering of other items in the trait. This code happily compiles:
But swapping the two items causes the above error:
Make sure to write each test in a separate trait to avoid other items messing with your testing. I initially thought the
ErrorTraitArg
example did not produce an error because I had put it into the same trait as other working examples.Potentially related issue
I found another issue, #88287, that produces the same error message. However, I'm not sure if that is the same bug because I could not get
Self::GatBounded<Self::AssociatedType>
to error in only the return type position. That issue's example also uses the TAIT feature (which I'm unfamiliar with) so I was unable to reduce it enough to see similarities to my example.Meta
rustc --version --verbose
:As well as rust playground
1.56.0-nightly (2021-08-25 0afc20860eb98a29d9bb)
@rustbot label +T-compiler +F-generic_associated_types +A-Traits +requires-nightly
The text was updated successfully, but these errors were encountered: