From b77d8fa12946472176094725055a07f9d0ce3440 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 25 Nov 2024 18:30:13 +0100 Subject: [PATCH] tests: Add recursive associated type bound regression tests --- .../129541-recursive-enum-and-array-impl.rs | 22 ++++++++++++++++++ ...29541-recursive-enum-and-array-impl.stderr | 10 ++++++++ .../129541-recursive-struct-and-array-impl.rs | 23 +++++++++++++++++++ .../solver-cycles/129541-recursive-struct.rs | 19 +++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.rs create mode 100644 tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.stderr create mode 100644 tests/ui/traits/solver-cycles/129541-recursive-struct-and-array-impl.rs create mode 100644 tests/ui/traits/solver-cycles/129541-recursive-struct.rs diff --git a/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.rs b/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.rs new file mode 100644 index 0000000000000..197207dfb4be8 --- /dev/null +++ b/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.rs @@ -0,0 +1,22 @@ +// Regression test for #129541 +//~^ ERROR cycle detected when computing layout of `<[Hello] as Normalize>::Assoc` [E0391] + +trait Bound {} +trait Normalize { + type Assoc; +} + +impl Normalize for T { + type Assoc = T; +} + +impl Normalize for [T] { + type Assoc = T; +} + +impl Bound for Hello {} +enum Hello { + Variant(<[Hello] as Normalize>::Assoc), +} + +fn main() {} diff --git a/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.stderr b/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.stderr new file mode 100644 index 0000000000000..50dcea0bfac69 --- /dev/null +++ b/tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.stderr @@ -0,0 +1,10 @@ +error[E0391]: cycle detected when computing layout of `<[Hello] as Normalize>::Assoc` + | + = note: ...which requires computing layout of `Hello`... + = note: ...which again requires computing layout of `<[Hello] as Normalize>::Assoc`, completing the cycle + = note: cycle used when computing layout of `Hello` + = 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`. diff --git a/tests/ui/traits/solver-cycles/129541-recursive-struct-and-array-impl.rs b/tests/ui/traits/solver-cycles/129541-recursive-struct-and-array-impl.rs new file mode 100644 index 0000000000000..defb39aae06d4 --- /dev/null +++ b/tests/ui/traits/solver-cycles/129541-recursive-struct-and-array-impl.rs @@ -0,0 +1,23 @@ +// Regression test for #129541 + +//@ check-pass + +trait Bound {} +trait Normalize { + type Assoc; +} + +impl Normalize for T { + type Assoc = T; +} + +impl Normalize for [T] { + type Assoc = T; +} + +impl Bound for Hello {} +struct Hello { + a: <[Hello] as Normalize>::Assoc, +} + +fn main() {} diff --git a/tests/ui/traits/solver-cycles/129541-recursive-struct.rs b/tests/ui/traits/solver-cycles/129541-recursive-struct.rs new file mode 100644 index 0000000000000..d4339dd54d6c7 --- /dev/null +++ b/tests/ui/traits/solver-cycles/129541-recursive-struct.rs @@ -0,0 +1,19 @@ +// Regression test for #129541 + +//@ check-pass + +trait Bound {} +trait Normalize { + type Assoc; +} + +impl Normalize for [T] { + type Assoc = T; +} + +impl Bound for Hello {} +struct Hello { + a: <[Hello] as Normalize>::Assoc, +} + +fn main() {}