Skip to content

Stack overflow when impl'ing on recursive types #15188

Closed
@apoelstra

Description

@apoelstra

See https://gist.github.com/apoelstra/0c5e05a2d57a91be3c0b

Here I have a structure like

struct List<T> {
data: T,
next: Option<Box<List<T>>>
}

and am trying to implement a deserialization trait on it. When I try to call deserialize on a Vec<u8> to produce a List<u8> say, rustc overflows, presumably chasing <T> through an infinite chain of Option<Box<List<T>>>s somehow.

Note that if the data field and parameter <T> are removed, there is no stack overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions