Add test cases for detecting structural recursion
This commit is contained in:
parent
309710dece
commit
ee882b3a4b
11
src/test/ui/issues/issue-74224.rs
Normal file
11
src/test/ui/issues/issue-74224.rs
Normal file
@ -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() {}
|
17
src/test/ui/issues/issue-74224.stderr
Normal file
17
src/test/ui/issues/issue-74224.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error[E0072]: recursive type `A` has infinite size
|
||||
--> $DIR/issue-74224.rs:1:1
|
||||
|
|
||||
LL | struct A<T> {
|
||||
| ^^^^^^^^^^^ recursive type has infinite size
|
||||
...
|
||||
LL | y: A<A<T>>,
|
||||
| ------- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
|
||||
|
|
||||
LL | y: Box<A<A<T>>>,
|
||||
| ^^^^ ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0072`.
|
11
src/test/ui/issues/issue-84611.rs
Normal file
11
src/test/ui/issues/issue-84611.rs
Normal file
@ -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() {}
|
17
src/test/ui/issues/issue-84611.stderr
Normal file
17
src/test/ui/issues/issue-84611.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error[E0072]: recursive type `Foo` has infinite size
|
||||
--> $DIR/issue-84611.rs:1:1
|
||||
|
|
||||
LL | struct Foo<T> {
|
||||
| ^^^^^^^^^^^^^ recursive type has infinite size
|
||||
LL |
|
||||
LL | x: Foo<[T; 1]>,
|
||||
| ----------- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
||||
|
|
||||
LL | x: Box<Foo<[T; 1]>>,
|
||||
| ^^^^ ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0072`.
|
23
src/test/ui/mutual-struct-recursion.rs
Normal file
23
src/test/ui/mutual-struct-recursion.rs
Normal file
@ -0,0 +1,23 @@
|
||||
struct A<T> {
|
||||
//~^ ERROR recursive type `A` has infinite size
|
||||
x: T,
|
||||
y: B<T>,
|
||||
}
|
||||
|
||||
struct B<T> {
|
||||
//~^ ERROR recursive type `B` has infinite size
|
||||
z: A<T>
|
||||
}
|
||||
|
||||
struct C<T> {
|
||||
//~^ ERROR recursive type `C` has infinite size
|
||||
x: T,
|
||||
y: Option<Option<D<T>>>,
|
||||
}
|
||||
|
||||
struct D<T> {
|
||||
//~^ ERROR recursive type `D` has infinite size
|
||||
z: Option<Option<C<T>>>,
|
||||
}
|
||||
|
||||
fn main() {}
|
59
src/test/ui/mutual-struct-recursion.stderr
Normal file
59
src/test/ui/mutual-struct-recursion.stderr
Normal file
@ -0,0 +1,59 @@
|
||||
error[E0072]: recursive type `A` has infinite size
|
||||
--> $DIR/mutual-struct-recursion.rs:1:1
|
||||
|
|
||||
LL | struct A<T> {
|
||||
| ^^^^^^^^^^^ recursive type has infinite size
|
||||
...
|
||||
LL | y: B<T>,
|
||||
| ---- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
|
||||
|
|
||||
LL | y: Box<B<T>>,
|
||||
| ^^^^ ^
|
||||
|
||||
error[E0072]: recursive type `B` has infinite size
|
||||
--> $DIR/mutual-struct-recursion.rs:7:1
|
||||
|
|
||||
LL | struct B<T> {
|
||||
| ^^^^^^^^^^^ recursive type has infinite size
|
||||
LL |
|
||||
LL | z: A<T>
|
||||
| ---- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `B` representable
|
||||
|
|
||||
LL | z: Box<A<T>>
|
||||
| ^^^^ ^
|
||||
|
||||
error[E0072]: recursive type `C` has infinite size
|
||||
--> $DIR/mutual-struct-recursion.rs:12:1
|
||||
|
|
||||
LL | struct C<T> {
|
||||
| ^^^^^^^^^^^ recursive type has infinite size
|
||||
...
|
||||
LL | y: Option<Option<D<T>>>,
|
||||
| -------------------- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `C` representable
|
||||
|
|
||||
LL | y: Box<Option<Option<D<T>>>>,
|
||||
| ^^^^ ^
|
||||
|
||||
error[E0072]: recursive type `D` has infinite size
|
||||
--> $DIR/mutual-struct-recursion.rs:18:1
|
||||
|
|
||||
LL | struct D<T> {
|
||||
| ^^^^^^^^^^^ recursive type has infinite size
|
||||
LL |
|
||||
LL | z: Option<Option<C<T>>>,
|
||||
| -------------------- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `D` representable
|
||||
|
|
||||
LL | z: Box<Option<Option<C<T>>>>,
|
||||
| ^^^^ ^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0072`.
|
Loading…
x
Reference in New Issue
Block a user