A struct or enum recursively contains itself with no indirection.
struct Node { next: Option<Node> }
// E0072: Node has infinite size (it contains itself)
Node would need to be big enough to hold another Node, which holds another, ad infinitum. Rust needs a fixed size at compile time.
- Box the recursive position: struct Node { next: Option<Box<Node>> } — Box is a fixed-size pointer.
- For shared ownership, use Rc/Arc: Option<Rc<Node>>.
- For graphs, switch to indices into an arena: Option<NodeId>.
- Single-link variants with no recursion can sometimes be flattened into a Vec.