diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2024-12-19 08:57:49 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-01-09 08:49:39 +0000 |
| commit | 37f2998c6e7eeac6a5e4f1aaec9ab353bb2f7b0b (patch) | |
| tree | aee635f4120c7ca09832aa9a15a1a51086170424 | |
| parent | 91b6b4e038b339982f8f7b79325a44f1a8cbb511 (diff) | |
| download | rust-37f2998c6e7eeac6a5e4f1aaec9ab353bb2f7b0b.tar.gz rust-37f2998c6e7eeac6a5e4f1aaec9ab353bb2f7b0b.zip | |
Use trait definition cycle detection for trait alias definitions, too
5 files changed, 35 insertions, 6 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 0c19e2e4c51..02ccdd834ae 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -653,7 +653,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( } } } - PredicateFilter::SelfAndAssociatedTypeBounds => { + PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => { for &(pred, span) in implied_bounds { debug!("superbound: {:?}", pred); if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder() diff --git a/tests/ui/infinite/infinite-trait-alias-recursion.rs b/tests/ui/infinite/infinite-trait-alias-recursion.rs index ec86744e68c..0bd4624de3f 100644 --- a/tests/ui/infinite/infinite-trait-alias-recursion.rs +++ b/tests/ui/infinite/infinite-trait-alias-recursion.rs @@ -1,7 +1,7 @@ #![feature(trait_alias)] trait T1 = T2; -//~^ ERROR cycle detected when computing the super predicates of `T1` +//~^ ERROR cycle detected when computing the implied predicates of `T1` trait T2 = T3; diff --git a/tests/ui/infinite/infinite-trait-alias-recursion.stderr b/tests/ui/infinite/infinite-trait-alias-recursion.stderr index b3980cb935e..5b0cbd58231 100644 --- a/tests/ui/infinite/infinite-trait-alias-recursion.stderr +++ b/tests/ui/infinite/infinite-trait-alias-recursion.stderr @@ -1,20 +1,20 @@ -error[E0391]: cycle detected when computing the super predicates of `T1` +error[E0391]: cycle detected when computing the implied predicates of `T1` --> $DIR/infinite-trait-alias-recursion.rs:3:12 | LL | trait T1 = T2; | ^^ | -note: ...which requires computing the super predicates of `T2`... +note: ...which requires computing the implied predicates of `T2`... --> $DIR/infinite-trait-alias-recursion.rs:6:12 | LL | trait T2 = T3; | ^^ -note: ...which requires computing the super predicates of `T3`... +note: ...which requires computing the implied predicates of `T3`... --> $DIR/infinite-trait-alias-recursion.rs:8:12 | LL | trait T3 = T1 + T3; | ^^ - = note: ...which again requires computing the super predicates of `T1`, completing the cycle + = note: ...which again requires computing the implied predicates of `T1`, completing the cycle = note: trait aliases cannot be recursive note: cycle used when checking that `T1` is well-formed --> $DIR/infinite-trait-alias-recursion.rs:3:1 diff --git a/tests/ui/traits/alias/infinite_normalization.rs b/tests/ui/traits/alias/infinite_normalization.rs new file mode 100644 index 00000000000..848afc1efb2 --- /dev/null +++ b/tests/ui/traits/alias/infinite_normalization.rs @@ -0,0 +1,11 @@ +//! This test used to get stuck in an infinite +//! recursion during normalization. +//! +//! issue: https://github.com/rust-lang/rust/issues/133901 + +#![feature(trait_alias)] +fn foo<T: Baz<i32>>() {} +trait Baz<A> = Baz<Option<A>>; +//~^ ERROR: cycle detected when computing the implied predicates of `Baz` + +fn main() {} diff --git a/tests/ui/traits/alias/infinite_normalization.stderr b/tests/ui/traits/alias/infinite_normalization.stderr new file mode 100644 index 00000000000..5fe423609e5 --- /dev/null +++ b/tests/ui/traits/alias/infinite_normalization.stderr @@ -0,0 +1,18 @@ +error[E0391]: cycle detected when computing the implied predicates of `Baz` + --> $DIR/infinite_normalization.rs:8:16 + | +LL | trait Baz<A> = Baz<Option<A>>; + | ^^^^^^^^^^^^^^ + | + = note: ...which immediately requires computing the implied predicates of `Baz` again + = note: trait aliases cannot be recursive +note: cycle used when computing normalized predicates of `foo` + --> $DIR/infinite_normalization.rs:7:1 + | +LL | fn foo<T: Baz<i32>>() {} + | ^^^^^^^^^^^^^^^^^^^^^ + = 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`. |
