The following code currently fails to compile:
enum Nested {
Zero,
One(Nested)
}
The error is:
error[E0072]: recursive type `Nested` has infinite size
--> src/lib.rs:3:1
|
3 | enum Nested {
| ^^^^^^^^^^^ recursive type has infinite size
4 | Zero,
5 | One(Nested)
| ------ recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Nested` representable
|
5 | One(Box<Nested>)
| ^^^^ ^
But this seems to be an odd way of putting it, because in order to get an 'infinite' size, you'd have to construct it in some sort of infinite loop. So I'm wondering why such a type could not instead be unsized, and require representation using a fat pointer that carries the nesting depth.
This would be a lot more convenient than boxing everything and/or setting up an arena and passing it around to ensure locality...