Repository: rust
Issue: rustc unexpectedly overflowed its stack! (Nested Datatypes)
Labels: A-debuginfo,I-ICE,T-compiler,C-bug,S-bug-has-test

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
// To prevent "overflow while adding drop-check rules".
use std::mem::ManuallyDrop;

pub enum Foo<U> {
    Leaf(U),

    Branch(BoxedFoo<BoxedFoo<U>>),
}

pub type BoxedFoo<U> = ManuallyDrop<Box<Foo<U>>>;

pub fn test() -> Foo<usize> {
    todo!()
}
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.74.0-nightly (65ea825f4 2023-09-18)
binary: rustc
commit-hash: 65ea825f4021eaf77f1b25139969712d65b435a4
commit-date: 2023-09-18
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0
```

### Error output

```
error: rustc interrupted by SIGSEGV, printing backtrace
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x3154476)[0x7fc55fbb1476]
/usr/lib/libc.so.6(+0x3e710)[0x7fc55c679710]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x14)[0x7fc55de39434]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13d7aab)[0x7fc55de34aab]

### cycle encountered after 7 frames with period 8
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
### recursed 31 times

<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]

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
note: backtrace dumped due to SIGSEGV! resuming signal
error: could not compile `rustc-bug` (lib)

Caused by:
  process didn't exit successfully: `<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rustc_bug --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=190 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b16d58bd391752b1 -C extra-filename=-b16d58bd391752b1 --out-dir <redacted>/rustc-bug/target/debug/deps -C incremental=<redacted>/rustc-bug/target/debug/incremental -L dependency=<redacted>/rustc-bug/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)
```

</p>
</details>

**Edit**: Simplified.