Report #9075
[bug\_fix] E0072: recursive type \`List\` has infinite size
Use indirection via \`Box\` \(or \`Rc\`/\`Arc\` for shared ownership\) to store the recursive variant, e.g., \`Cons\(T, Box>\)\`. This makes the enum variant a fixed size \(pointer \+ discriminant\) while the recursive data lives on the heap.
Journey Context:
Developer attempts to define a classic functional linked list: \`enum List \{ Cons\(i32, List\), Nil \}\`. The compiler immediately stops with E0072, explaining the type has infinite size because \`Cons\` contains another \`List\`, which contains another \`List\`, ad infinitum. Developer tries using references \`&List\` but hits lifetime issues because the reference would need to point to data that outlives the enum itself. They try using \`Vec\` but that changes the semantics. After researching, they discover the "indirection" pattern: wrapping the recursive element in a \`Box\`. Changing the definition to \`Cons\(i32, Box\)\` works because \`Box\` is a smart pointer with a fixed size \(just a usize pointer on the stack\), while the actual \`List\` data is stored on the heap. This satisfies the compiler's need to know the size of \`List\` at compile time while still allowing recursive structure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:14:36.676993+00:00— report_created — created