Repository: rust
Issue: stack overflow in `rustc_ty_utils::opaque_types::OpaqueTypeCollector as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty::{closure#0}`
Labels: I-crash,T-compiler,A-impl-trait,C-bug

<!--
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
struct Foo<F: FnOnce(T), F: FnOnce(T)> {
    f: FooImpl,
}

type FooImpl = Foo<FooImpl, impl FnOnce(ImplT)>;

fn bar() -> FooImpl {}

```

does not seem to be fixed by the new solver

### 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.80.0-nightly (faefc618c 2024-05-07)
binary: rustc
commit-hash: faefc618cf48bd794cbc808448df1bf3f59f36af
commit-date: 2024-05-07
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
```

### Error output

```
<output>
```

<!--
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>

```
error[E0403]: the name `F` is already used for a generic parameter in this item's generic parameters
 --> ice.rs:1:26
  |
1 | struct Foo<F: FnOnce(T), F: FnOnce(T)> {
  |            -             ^ already used
  |            |
  |            first use of `F`

error[E0412]: cannot find type `T` in this scope
 --> ice.rs:1:22
  |
1 | struct Foo<F: FnOnce(T), F: FnOnce(T)> {
  |                      ^ not found in this scope

error[E0412]: cannot find type `T` in this scope
 --> ice.rs:1:36
  |
1 | struct Foo<F: FnOnce(T), F: FnOnce(T)> {
  |                                    ^ not found in this scope

error[E0412]: cannot find type `ImplT` in this scope
 --> ice.rs:5:41
  |
5 | type FooImpl = Foo<FooImpl, impl FnOnce(ImplT)>;
  |                                         ^^^^^ not found in this scope
  |
help: you might be missing a type parameter
  |
5 | type FooImpl<ImplT> = Foo<FooImpl, impl FnOnce(ImplT)>;
  |             +++++++

error[E0658]: `impl Trait` in type aliases is unstable
 --> ice.rs:5:29
  |
5 | type FooImpl = Foo<FooImpl, impl FnOnce(ImplT)>;
  |                             ^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
  = note: this compiler was built on 2024-05-07; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `ice`
 --> ice.rs:7:23
  |
7 | fn bar() -> FooImpl {}
  |                       ^ consider adding a `main` function to `ice.rs`

error[E0275]: overflow normalizing the type alias `FooImpl`
 --> ice.rs:2:8
  |
2 |     f: FooImpl,
  |        ^^^^^^^
  |
  = note: in case this is a recursive type alias, consider using a struct, enum, or union instead

error[E0275]: overflow normalizing the type alias `FooImpl`
 --> ice.rs:5:16
  |
5 | type FooImpl = Foo<FooImpl, impl FnOnce(ImplT)>;
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: in case this is a recursive type alias, consider using a struct, enum, or union instead

error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x30d8ca6)[0x7f697f2d8ca6]
/usr/lib/libc.so.6(+0x40770)[0x7f697c05a770]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489a5bc)[0x7f6980a9a5bc]

### cycle encountered after 3 frames with period 4
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489a60d)[0x7f6980a9a60d]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489b76f)[0x7f6980a9b76f]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489a60d)[0x7f6980a9a60d]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489b76f)[0x7f6980a9b76f]
### recursed 63 times

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-baba34ae40c356f7.so(+0x489a60d)[0x7f6980a9a60d]

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
[1]    135140 segmentation fault  rustc ice.rs
```

</p>
</details>