1
Fork 0

Rollup merge of #121409 - compiler-errors:atb-cycle, r=cjgillot

Prevent cycle in implied predicates computation

Makes #65913 from hang -> fail. I believe fail is the correct state for this test to remain for the long term.
This commit is contained in:
Matthias Krüger 2024-02-25 17:05:22 +01:00 committed by GitHub
commit 4d442f5a58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 8 deletions

View file

@ -640,16 +640,30 @@ pub(super) fn implied_predicates_with_filter(
// Now require that immediate supertraits are converted, which will, in
// turn, reach indirect supertraits, so we detect cycles now instead of
// overflowing during elaboration.
if matches!(filter, PredicateFilter::SelfOnly) {
for &(pred, span) in implied_bounds {
debug!("superbound: {:?}", pred);
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
&& bound.polarity == ty::ImplPolarity::Positive
{
tcx.at(span).super_predicates_of(bound.def_id());
// overflowing during elaboration. Same for implied predicates, which
// make sure we walk into associated type bounds.
match filter {
PredicateFilter::SelfOnly => {
for &(pred, span) in implied_bounds {
debug!("superbound: {:?}", pred);
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
&& bound.polarity == ty::ImplPolarity::Positive
{
tcx.at(span).super_predicates_of(bound.def_id());
}
}
}
PredicateFilter::SelfAndAssociatedTypeBounds => {
for &(pred, span) in implied_bounds {
debug!("superbound: {:?}", pred);
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
&& bound.polarity == ty::ImplPolarity::Positive
{
tcx.at(span).implied_predicates_of(bound.def_id());
}
}
}
_ => {}
}
ty::GenericPredicates { parent: None, predicates: implied_bounds }