S0038: cyclic user-defined type
Generated from rellum-diagnostics/src/db.rs.
Explanation
User-defined records and enums are stored by value. A direct cycle between named types would require a value to contain itself with no finite size, so the compiler rejects cyclic type definitions.
Common causes
- a record field directly references its own type
- two or more records reference each other by value
- an enum variant payload completes a cycle through another named type
Canonical fixes
- break the cycle by storing an identifier or index instead of the full value
Before:
type Node = { next: Node }
After:
type Node = { next_id: Int }
- use an acyclic payload shape
Code example
type Node = { next: Node }