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

stack overflow with "recursive" trait bound on an associated type #20551

Closed
sellibitze opened this issue Jan 5, 2015 · 3 comments
Closed

stack overflow with "recursive" trait bound on an associated type #20551

sellibitze opened this issue Jan 5, 2015 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@sellibitze
Copy link
Contributor

I just tried this (last time was 2015-01-08) on playpen:

trait Trait {
    type AssocType: Trait;
}
fn main() {}

which apparently makes rustc do an infinite recursion (or something) ending in a stack overflow:

thread 'rustc' has overflowed its stack
Illegal instruction (core dumped)
playpen: application terminated with error code 132

If I remove the : Trait in the line for the associated type, it works again.

@kmcallister kmcallister added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-associated-items Area: Associated items (types, constants & functions) labels Jan 5, 2015
@AndyShiue
Copy link

Recursive trait declaration always crashes rustc,
even trait T: T {} can do it...

@carllerche
Copy link
Member

cc me

@quantheory
Copy link
Contributor

Note that such traits should probably (?) be accepted, but not all impls of traits can be accepted:

trait Foo {
    type Bar: Foo;
}
// This seems fine.
impl Foo for Baz {
    type Bar = Self;
}
// Problematic
impl<T> Foo for Buzz<T> {
    type Bar = Buzz<Self>;
}

You can make the situation much worse with multiple traits that reference each other, of course. Presumably we have to have some recursion limit that stops types from being infinitely nestable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants