Closed
Description
struct Foo<T> {
x: Foo<[T; 1]>,
y: T,
}
struct Bar {
x: Foo<Bar>,
}
has the following output:
error[E0072]: recursive type `Foo` has infinite size
--> src/lib.rs:1:1
|
1 | struct Foo<T> {
| ^^^^^^^^^^^^^ recursive type has infinite size
2 | x: Foo<[T; 1]>,
| ----------- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
2 | x: Box<Foo<[T; 1]>>,
| ^^^^ ^
thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
the stack overflow should not happen ^^
Activity
lcnr commentedon Apr 27, 2021
the recursion happens in
rust/compiler/rustc_middle/src/ty/util.rs
Lines 1001 to 1017 in e188693
Because
Foo
is not trivially self recursive this check is never hit and we keep looking intoFoo<[Bar; 1]>
,Foo<[[Bar; 1]; 1]>
and so on.lcnr commentedon Apr 27, 2021
cc #74224
Rollup merge of rust-lang#85012 - FabianWolff:struct-rec, r=davidtwco
Auto merge of rust-lang#85012 - FabianWolff:struct-rec, r=davidtwco