diff options
Diffstat (limited to 'tests/ui/structs-enums/struct-rec')
6 files changed, 126 insertions, 0 deletions
diff --git a/tests/ui/structs-enums/struct-rec/issue-74224.rs b/tests/ui/structs-enums/struct-rec/issue-74224.rs new file mode 100644 index 000000000..f3b72c5df --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/issue-74224.rs @@ -0,0 +1,11 @@ +struct A<T> { +//~^ ERROR recursive type `A` has infinite size + x: T, + y: A<A<T>>, +} + +struct B { + z: A<usize> +} + +fn main() {} diff --git a/tests/ui/structs-enums/struct-rec/issue-74224.stderr b/tests/ui/structs-enums/struct-rec/issue-74224.stderr new file mode 100644 index 000000000..f1d50bc8a --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/issue-74224.stderr @@ -0,0 +1,17 @@ +error[E0072]: recursive type `A` has infinite size + --> $DIR/issue-74224.rs:1:1 + | +LL | struct A<T> { + | ^^^^^^^^^^^ +... +LL | y: A<A<T>>, + | ------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | y: Box<A<A<T>>>, + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/tests/ui/structs-enums/struct-rec/issue-84611.rs b/tests/ui/structs-enums/struct-rec/issue-84611.rs new file mode 100644 index 000000000..4c356af3e --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/issue-84611.rs @@ -0,0 +1,11 @@ +struct Foo<T> { +//~^ ERROR recursive type `Foo` has infinite size + x: Foo<[T; 1]>, + y: T, +} + +struct Bar { + x: Foo<Bar>, +} + +fn main() {} diff --git a/tests/ui/structs-enums/struct-rec/issue-84611.stderr b/tests/ui/structs-enums/struct-rec/issue-84611.stderr new file mode 100644 index 000000000..536f54e3e --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/issue-84611.stderr @@ -0,0 +1,17 @@ +error[E0072]: recursive type `Foo` has infinite size + --> $DIR/issue-84611.rs:1:1 + | +LL | struct Foo<T> { + | ^^^^^^^^^^^^^ +LL | +LL | x: Foo<[T; 1]>, + | ----------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | x: Box<Foo<[T; 1]>>, + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.rs b/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.rs new file mode 100644 index 000000000..3bfce8b4f --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.rs @@ -0,0 +1,21 @@ +struct A<T> { +//~^ ERROR recursive types `A` and `B` have infinite size + x: T, + y: B<T>, +} + +struct B<T> { + z: A<T> +} + +struct C<T> { +//~^ ERROR recursive types `C` and `D` have infinite size + x: T, + y: Option<Option<D<T>>>, +} + +struct D<T> { + z: Option<Option<C<T>>>, +} + +fn main() {} diff --git a/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr b/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr new file mode 100644 index 000000000..881bc2819 --- /dev/null +++ b/tests/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr @@ -0,0 +1,49 @@ +error[E0072]: recursive types `A` and `B` have infinite size + --> $DIR/mutual-struct-recursion.rs:1:1 + | +LL | struct A<T> { + | ^^^^^^^^^^^ +... +LL | y: B<T>, + | ---- recursive without indirection +... +LL | struct B<T> { + | ^^^^^^^^^^^ +LL | z: A<T> + | ---- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL ~ y: Box<B<T>>, +LL | } +LL | +LL | struct B<T> { +LL ~ z: Box<A<T>> + | + +error[E0072]: recursive types `C` and `D` have infinite size + --> $DIR/mutual-struct-recursion.rs:11:1 + | +LL | struct C<T> { + | ^^^^^^^^^^^ +... +LL | y: Option<Option<D<T>>>, + | ---- recursive without indirection +... +LL | struct D<T> { + | ^^^^^^^^^^^ +LL | z: Option<Option<C<T>>>, + | ---- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL ~ y: Option<Option<Box<D<T>>>>, +LL | } +LL | +LL | struct D<T> { +LL ~ z: Option<Option<Box<C<T>>>>, + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0072`. |