Skip to content

Stack overflow declaring mutually recursive traits #11824

Closed
@erickt

Description

@erickt

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() { }

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions