Skip to content

Type defined inside impl block that mentions that same type causes stack overflow #145698

@theemathas

Description

@theemathas

Code

#![feature(type_alias_impl_trait)]

pub struct Wrap<T>(T);

type Opaque = impl Sized;

impl Wrap<Opaque> {
    #[define_opaque(Opaque)]
    fn make_opaque() -> Opaque {
        struct Thing;
        Thing
    }
}

fn main() {
    Wrap::<Opaque>::make_opaque();
}

See also #145696, which also has a type defined inside an impl block.

@rustbot labels +F-type_alias_impl_trait

Meta

Reproducible on the playground with version 1.91.0-nightly (2025-08-20 040a98af70f0a7da03f3)

Error output

error: rustc interrupted by SIGSEGV, printing backtrace
Backtrace

/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x3c8f99f)[0x75aafc28f99f]
/lib/x86_64-linux-gnu/libc.so.6(+0x45330)[0x75aaf8433330]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d34663)[0x75aafe334663]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d35061)[0x75aafe335061]

### cycle encountered after 4 frames with period 6
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d32b10)[0x75aafe332b10]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d3580f)[0x75aafe33580f]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d3483c)[0x75aafe33483c]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d3483c)[0x75aafe33483c]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d32b10)[0x75aafe332b10]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d936418e0c826e1.so(+0x5d350f9)[0x75aafe3350f9]
### recursed 42 times


note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
error: could not compile `playground` (bin "playground")

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions