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 declaring mutually recursive traits #11824

Closed
erickt opened this issue Jan 26, 2014 · 3 comments
Closed

Stack overflow declaring mutually recursive traits #11824

erickt opened this issue Jan 26, 2014 · 3 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@erickt
Copy link
Contributor

erickt commented Jan 26, 2014

This code causes rustc's stack to overflow:

trait Hash<H: Hasher> { }
trait Hasher<H: Hash> { }

trait StreamHash<H: StreamHasher>: Hash<H> { }
trait StreamHasher<H: StreamHash>: Hasher<H> { }

fn main() {
}

As a workaround, you can break up the recursion with another trait:

trait Hash { }
trait Hasher<H: Hash> { }

trait Stream { }
trait StreamHash<S: Stream>: Hash { }
trait StreamHasher<H: StreamHash<Self>>: Stream + Hasher<H> { }

fn main() { }
@reem
Copy link
Contributor

reem commented Sep 6, 2014

There seems to have been no progress on this issue. Does anyone know what might be the source of the problem or what could be done to fix it?

@frewsxcv
Copy link
Member

trait Hash<H: Hasher<Self>> {
    fn f(&self, _: H) {}
}

trait Hasher<H: Hash<Self>> {
    fn g(&self, _: H) {}
}

trait StreamHash<H: StreamHasher<Self>>: Hash<H> {
    fn h(&self, _: H) {}
}

trait StreamHasher<H: StreamHash<Self>>: Hasher<H> {
    fn i(&self, _: H) {}
}

fn main() {
}

I updated the original code block to compile with the latest Rust. I had to add methods for each trait to avoid the compiler complaining about unused type parameters. Also had to add <Self> to all the inherited trait types. That said, this compiles and runs for me with no stack overflows. Is this issue still valid or is my code rewrite not equivalent to the original example?

@tamird
Copy link
Contributor

tamird commented Apr 21, 2015

No longer reproducible.

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 1, 2023
…Alexendoo

Update rust-cache GHA in deploy workflow

This action was way outdated, produced a lot of warnings and didn't seem to work anymore.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

5 participants