Skip to content

Commit 37f2998

Browse files
committed
Use trait definition cycle detection for trait alias definitions, too
1 parent 91b6b4e commit 37f2998

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
653653
}
654654
}
655655
}
656-
PredicateFilter::SelfAndAssociatedTypeBounds => {
656+
PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
657657
for &(pred, span) in implied_bounds {
658658
debug!("superbound: {:?}", pred);
659659
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()

tests/ui/infinite/infinite-trait-alias-recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(trait_alias)]
22

33
trait T1 = T2;
4-
//~^ ERROR cycle detected when computing the super predicates of `T1`
4+
//~^ ERROR cycle detected when computing the implied predicates of `T1`
55

66
trait T2 = T3;
77

tests/ui/infinite/infinite-trait-alias-recursion.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0391]: cycle detected when computing the super predicates of `T1`
1+
error[E0391]: cycle detected when computing the implied predicates of `T1`
22
--> $DIR/infinite-trait-alias-recursion.rs:3:12
33
|
44
LL | trait T1 = T2;
55
| ^^
66
|
7-
note: ...which requires computing the super predicates of `T2`...
7+
note: ...which requires computing the implied predicates of `T2`...
88
--> $DIR/infinite-trait-alias-recursion.rs:6:12
99
|
1010
LL | trait T2 = T3;
1111
| ^^
12-
note: ...which requires computing the super predicates of `T3`...
12+
note: ...which requires computing the implied predicates of `T3`...
1313
--> $DIR/infinite-trait-alias-recursion.rs:8:12
1414
|
1515
LL | trait T3 = T1 + T3;
1616
| ^^
17-
= note: ...which again requires computing the super predicates of `T1`, completing the cycle
17+
= note: ...which again requires computing the implied predicates of `T1`, completing the cycle
1818
= note: trait aliases cannot be recursive
1919
note: cycle used when checking that `T1` is well-formed
2020
--> $DIR/infinite-trait-alias-recursion.rs:3:1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! This test used to get stuck in an infinite
2+
//! recursion during normalization.
3+
//!
4+
//! issue: https://github.com/rust-lang/rust/issues/133901
5+
6+
#![feature(trait_alias)]
7+
fn foo<T: Baz<i32>>() {}
8+
trait Baz<A> = Baz<Option<A>>;
9+
//~^ ERROR: cycle detected when computing the implied predicates of `Baz`
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0391]: cycle detected when computing the implied predicates of `Baz`
2+
--> $DIR/infinite_normalization.rs:8:16
3+
|
4+
LL | trait Baz<A> = Baz<Option<A>>;
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: ...which immediately requires computing the implied predicates of `Baz` again
8+
= note: trait aliases cannot be recursive
9+
note: cycle used when computing normalized predicates of `foo`
10+
--> $DIR/infinite_normalization.rs:7:1
11+
|
12+
LL | fn foo<T: Baz<i32>>() {}
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
= 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
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)