Repository: rust
Issue: stack overflow during debuginfo generation
Labels: I-crash,A-debuginfo,P-medium,T-compiler,regression-from-stable-to-stable,C-bug,S-bug-has-test

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
use std::marker::PhantomData;

struct Digit<T> {
    elem: T
}

struct Node<T:'static> { m: PhantomData<&'static T> }

enum FingerTree<T:'static> {
    Single(T),

    Deep(
        Digit<T>,
        Node<FingerTree<Node<T>>>,
        )
}

enum Wrapper<T:'static> {
    Simple,
    Other(FingerTree<T>),
}

fn main() {
    let w =
        Some(Wrapper::Simple::<u32>);

}
```
This builds until you go for `-Cdebuginfo=2`

### 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.78.0-nightly (8f359beca 2024-02-23)
binary: rustc
commit-hash: 8f359beca4e58bc3ae795a666301a8f47023044c
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x2e9fcb3)[0x7f2de429fcb3]
/usr/lib/libc.so.6(+0x40770)[0x7f2de1131770]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(_RNvNtNtCsiCYefPgEVI8_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x1b)[0x7f2de5629ddb]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(_RNvNtNtCsiCYefPgEVI8_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x1b4)[0x7f2de5629f74]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a70)[0x7f2de5907a70]

### cycle encountered after 5 frames with period 6
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a8b)[0x7f2de5907a8b]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a8b)[0x7f2de5907a8b]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a8b)[0x7f2de5907a8b]
### recursed 41 times

/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a8b)[0x7f2de5907a8b]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x4507a8b)[0x7f2de5907a8b]
/home/matthias/.rustup/toolchains/master/lib/librustc_driver-3110cac9722aa818.so(+0x450674f)[0x7f2de590674f]

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
[1]    3369027 segmentation fault  rustc crash.rs -Cdebuginfo=2
```

</p>
</details>