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
{{ message }}
Repository navigation
Cycle detected when using associated type bounds in super trait #65913
error[E0277]: the trait bound `<<SelfasA>::TasA>::T:B` is not satisfied
One might think that this should compile because <<Self as A>::T as A>::T: B should flow from the mere fact that Self::T: B holds which should hold by Self: B. However, the compiler isn't smart enough to take these implied bounds into account. When it comes to the special case of type T: C;, the compiler is able to do that however.
What is curious here is that rather than getting the error message about "not satisfied", we are getting a cycle error. cc @alexreg@nikomatsakis@tmandry
I wonder if the supertraits query is including the associated type bound - AFAIK it should only include the bounds specified on Self itself, not associated types of Self or other types.
@eddyb I know that was a problem previously, though I introduced a filter in relevant places to combat it. We may need to introduce a filter in another place.
As of #110512, this is no longer a cycle error, and the code above errors with:
error[E0277]: the trait bound `<<Self as A>::T as A>::T: B` is not satisfied
--> /home/../test.rs:7:15
|
7 | trait B: A<T: B> {}
| ^ the trait `B` is not implemented for `<<Self as A>::T as A>::T`
|
note: required by a bound in `B`
--> /home/../test.rs:7:15
|
7 | trait B: A<T: B> {}
| ^ required by this bound in `B`
help: consider further restricting the associated type
|
7 | trait B: A<T: B> where <<Self as A>::T as A>::T: B {}
| +++++++++++++++++++++++++++++++++
The fact that this still errors is a somewhat unfortunate side-effect of #65913 (comment), since the <Self as A>::T: B bound is not implied by the supertrait bounds.
Fixing this in a way that doesn't cause the compiler to overflow generating an infinite nested set of <<<<<<... as A>::T as A>::T as A>::T as A>::T as A>::T as A>::T: B bounds is gonna be pretty difficult, though.
I don't believe this will ever be made to compile. A cycle error IMO is the correct state for this. Diagnostics could perhaps be improved, but they would need to explain some details about how supertrait bound elaboration works.
Activity
Centril commentedon Oct 29, 2019
When we write:
this is equivalent to:
which is equivalent to:
This results in an error:
One might think that this should compile because
<<Self as A>::T as A>::T: Bshould flow from the mere fact thatSelf::T: Bholds which should hold bySelf: B. However, the compiler isn't smart enough to take these implied bounds into account. When it comes to the special case oftype T: C;, the compiler is able to do that however.What is curious here is that rather than getting the error message about "not satisfied", we are getting a cycle error. cc @alexreg @nikomatsakis @tmandry
eddyb commentedon Oct 29, 2019
I wonder if the supertraits query is including the associated type bound - AFAIK it should only include the bounds specified on
Selfitself, not associated types ofSelfor other types.alexreg commentedon Oct 29, 2019
@eddyb I know that was a problem previously, though I introduced a filter in relevant places to combat it. We may need to introduce a filter in another place.
jendrikw commentedon Jun 27, 2020
This issues still happens, are there any updates on fixes?
compiler-errors commentedon May 7, 2023
As of #110512, this is no longer a cycle error, and the code above errors with:
The fact that this still errors is a somewhat unfortunate side-effect of #65913 (comment), since the
<Self as A>::T: Bbound is not implied by the supertrait bounds.Fixing this in a way that doesn't cause the compiler to overflow generating an infinite nested set of
<<<<<<... as A>::T as A>::T as A>::T as A>::T as A>::T as A>::T: Bbounds is gonna be pretty difficult, though.fmease commentedon Aug 21, 2023
This now hangs on nightly (not only the sugared form but also the desugared one) with both the old and the new solver.
@rustbot label I-hang E-needs-bisection
fmease commentedon Aug 21, 2023
Regressed in #112629 (git-revert: hang → errors). CC @compiler-errors
@rustbot label -E-needs-bisection
Rollup merge of rust-lang#121409 - compiler-errors:atb-cycle, r=cjgillot
Unrolled build for rust-lang#121409
compiler-errors commentedon Mar 6, 2024
I don't believe this will ever be made to compile. A cycle error IMO is the correct state for this. Diagnostics could perhaps be improved, but they would need to explain some details about how supertrait bound elaboration works.