Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive type results in infinite recursion #32619

Closed
dlrobertson opened this issue Mar 30, 2016 · 5 comments
Closed

Recursive type results in infinite recursion #32619

dlrobertson opened this issue Mar 30, 2016 · 5 comments

Comments

@dlrobertson
Copy link
Contributor

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.

@nagisa
Copy link
Member

nagisa commented Mar 30, 2016

This yields the expected error on stable.

That being said, I think this is the same bug as #32326.

cc @nikomatsakis, what do you think?

@dlrobertson
Copy link
Contributor Author

Ah, thanks. Missed that one in my search of possibly related bugs. FYI this isn't restricted to just enums. It also occurs with

struct Foo<T> {
    one: Bar<T>,
    two: Bar<T>
}
struct Bar<T> {
    foo: Foo<T>
}

Sorry, should have mentioned this in the initial report.

@nagisa
Copy link
Member

nagisa commented Mar 30, 2016

@danlrobertson my intuition tells me that this is the same bug nevertheless, but I’m waiting for @nikomatsakis to confirm it.

EDIT: in the linked bug Plus(Expr, Expr) should be pretty similar behaviourly to struct Newtype(Bar, Bar) which is equivalent to struct Foo { one: Bar, two: Bar }.

@dlrobertson
Copy link
Contributor Author

Ah! True... Good point... Still a bit of a newbie here

@nikomatsakis
Copy link
Contributor

I agree this is a dup of #32326 (and have confirmed that my fix for #32326 fixes it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants