Skip to content

Recursive type results in infinite recursion #32619

Closed
@dlrobertson

Description

@dlrobertson

Given the following recursive type.

struct Foo<T> {
    one: Bar<T>,
    two: Bar<T>
}
enum Bar<T> {
    Foo(Foo<T>),
    Baz(T)
}

rustc will recurse over fulfill::process_predicate1 until out of memory. A brief look at RUST_LOG="debug" ... shows.

INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
INFO:rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<Bar<T> as core::marker::Sized>))` at depth 22 yielded Ok(Some)
...

Reproducible on b678600 and 70b8b94

Interestingly, if Foo::two is commented out the expected error is thrown. This might be related to #22672? After some inspection with gdb it looks like it passes the type checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions