Type defined inside impl block that mentions that same type causes stack overflow
Open
Nobody has claimed this yet.
C-bug
I-crash
regression-from-stable-to-stable
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/rust-lang/rust/issues/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")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the provided nightly Rust reproducer and compare its behavior with issue #145696. Use the reported rustc stack-overflow backtrace to locate the recursive compiler path; done means this case no longer overflows the compiler stack and has a regression test covering the reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100