Prevent cycle in implied predicates computation
This commit is contained in:
parent
1d447a9946
commit
6edbc8d875
3 changed files with 49 additions and 8 deletions
|
@ -640,16 +640,30 @@ pub(super) fn implied_predicates_with_filter(
|
||||||
|
|
||||||
// Now require that immediate supertraits are converted, which will, in
|
// Now require that immediate supertraits are converted, which will, in
|
||||||
// turn, reach indirect supertraits, so we detect cycles now instead of
|
// turn, reach indirect supertraits, so we detect cycles now instead of
|
||||||
// overflowing during elaboration.
|
// overflowing during elaboration. Same for implied predicates, which
|
||||||
if matches!(filter, PredicateFilter::SelfOnly) {
|
// make sure we walk into associated type bounds.
|
||||||
for &(pred, span) in implied_bounds {
|
match filter {
|
||||||
debug!("superbound: {:?}", pred);
|
PredicateFilter::SelfOnly => {
|
||||||
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
|
for &(pred, span) in implied_bounds {
|
||||||
&& bound.polarity == ty::ImplPolarity::Positive
|
debug!("superbound: {:?}", pred);
|
||||||
{
|
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
|
||||||
tcx.at(span).super_predicates_of(bound.def_id());
|
&& 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 }
|
ty::GenericPredicates { parent: None, predicates: implied_bounds }
|
||||||
|
|
10
tests/ui/associated-type-bounds/implied-bounds-cycle.rs
Normal file
10
tests/ui/associated-type-bounds/implied-bounds-cycle.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#![feature(associated_type_bounds)]
|
||||||
|
|
||||||
|
trait A {
|
||||||
|
type T;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait B: A<T: B> {}
|
||||||
|
//~^ ERROR cycle detected when computing the implied predicates of `B`
|
||||||
|
|
||||||
|
fn main() {}
|
17
tests/ui/associated-type-bounds/implied-bounds-cycle.stderr
Normal file
17
tests/ui/associated-type-bounds/implied-bounds-cycle.stderr
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
error[E0391]: cycle detected when computing the implied predicates of `B`
|
||||||
|
--> $DIR/implied-bounds-cycle.rs:7:15
|
||||||
|
|
|
||||||
|
LL | trait B: A<T: B> {}
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: ...which immediately requires computing the implied predicates of `B` again
|
||||||
|
note: cycle used when computing normalized predicates of `B`
|
||||||
|
--> $DIR/implied-bounds-cycle.rs:7:1
|
||||||
|
|
|
||||||
|
LL | trait B: A<T: B> {}
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0391`.
|
Loading…
Add table
Add a link
Reference in a new issue