Skip to content

Commit ee882b3

Browse files
committed
Add test cases for detecting structural recursion
1 parent 309710d commit ee882b3

6 files changed

+138
-0
lines changed

src/test/ui/issues/issue-74224.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct A<T> {
2+
//~^ ERROR recursive type `A` has infinite size
3+
x: T,
4+
y: A<A<T>>,
5+
}
6+
7+
struct B {
8+
z: A<usize>
9+
}
10+
11+
fn main() {}

src/test/ui/issues/issue-74224.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0072]: recursive type `A` has infinite size
2+
--> $DIR/issue-74224.rs:1:1
3+
|
4+
LL | struct A<T> {
5+
| ^^^^^^^^^^^ recursive type has infinite size
6+
...
7+
LL | y: A<A<T>>,
8+
| ------- recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
11+
|
12+
LL | y: Box<A<A<T>>>,
13+
| ^^^^ ^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0072`.

src/test/ui/issues/issue-84611.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Foo<T> {
2+
//~^ ERROR recursive type `Foo` has infinite size
3+
x: Foo<[T; 1]>,
4+
y: T,
5+
}
6+
7+
struct Bar {
8+
x: Foo<Bar>,
9+
}
10+
11+
fn main() {}

src/test/ui/issues/issue-84611.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0072]: recursive type `Foo` has infinite size
2+
--> $DIR/issue-84611.rs:1:1
3+
|
4+
LL | struct Foo<T> {
5+
| ^^^^^^^^^^^^^ recursive type has infinite size
6+
LL |
7+
LL | x: Foo<[T; 1]>,
8+
| ----------- recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
11+
|
12+
LL | x: Box<Foo<[T; 1]>>,
13+
| ^^^^ ^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0072`.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
struct A<T> {
2+
//~^ ERROR recursive type `A` has infinite size
3+
x: T,
4+
y: B<T>,
5+
}
6+
7+
struct B<T> {
8+
//~^ ERROR recursive type `B` has infinite size
9+
z: A<T>
10+
}
11+
12+
struct C<T> {
13+
//~^ ERROR recursive type `C` has infinite size
14+
x: T,
15+
y: Option<Option<D<T>>>,
16+
}
17+
18+
struct D<T> {
19+
//~^ ERROR recursive type `D` has infinite size
20+
z: Option<Option<C<T>>>,
21+
}
22+
23+
fn main() {}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
error[E0072]: recursive type `A` has infinite size
2+
--> $DIR/mutual-struct-recursion.rs:1:1
3+
|
4+
LL | struct A<T> {
5+
| ^^^^^^^^^^^ recursive type has infinite size
6+
...
7+
LL | y: B<T>,
8+
| ---- recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
11+
|
12+
LL | y: Box<B<T>>,
13+
| ^^^^ ^
14+
15+
error[E0072]: recursive type `B` has infinite size
16+
--> $DIR/mutual-struct-recursion.rs:7:1
17+
|
18+
LL | struct B<T> {
19+
| ^^^^^^^^^^^ recursive type has infinite size
20+
LL |
21+
LL | z: A<T>
22+
| ---- recursive without indirection
23+
|
24+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `B` representable
25+
|
26+
LL | z: Box<A<T>>
27+
| ^^^^ ^
28+
29+
error[E0072]: recursive type `C` has infinite size
30+
--> $DIR/mutual-struct-recursion.rs:12:1
31+
|
32+
LL | struct C<T> {
33+
| ^^^^^^^^^^^ recursive type has infinite size
34+
...
35+
LL | y: Option<Option<D<T>>>,
36+
| -------------------- recursive without indirection
37+
|
38+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `C` representable
39+
|
40+
LL | y: Box<Option<Option<D<T>>>>,
41+
| ^^^^ ^
42+
43+
error[E0072]: recursive type `D` has infinite size
44+
--> $DIR/mutual-struct-recursion.rs:18:1
45+
|
46+
LL | struct D<T> {
47+
| ^^^^^^^^^^^ recursive type has infinite size
48+
LL |
49+
LL | z: Option<Option<C<T>>>,
50+
| -------------------- recursive without indirection
51+
|
52+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `D` representable
53+
|
54+
LL | z: Box<Option<Option<C<T>>>>,
55+
| ^^^^ ^
56+
57+
error: aborting due to 4 previous errors
58+
59+
For more information about this error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)