Skip to content

checking for structural recursion can cause a stack overflow #84611

Closed
@lcnr

Description

@lcnr
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 ^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions