Repository: rust
Issue: ICE: `Failed to normalize Alias(Opaque, AliasTy {`
Labels: 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
mod impl_trait_mod {
    use super::*;
    pub type OpaqueBlock = impl Trait;
    pub type OpaqueIf = impl Trait;

    pub struct BlockWrapper(OpaqueBlock);
    pub struct IfWrapper(pub OpaqueIf);

    pub fn if_impl() -> Parser<OpaqueIf> {
        bind(option(block()), |_| block())
    }
}
use impl_trait_mod::*;

pub trait Trait {
    type Assoc;
}
pub struct Parser<P>(P);
pub struct Bind<P, F>(P, F);
impl<P, F> Trait for Bind<P, F> { type Assoc = (); }
impl Trait for BlockWrapper { type Assoc = (); }
impl Trait for IfWrapper { type Assoc = (); }

pub fn block() -> Parser<BlockWrapper> {
    loop {}
}
pub fn option<P: Trait>(arg: Parser<P>) -> Parser<impl Trait> {
    bind(arg, |_| block())
}
fn bind<P: Trait, P2, F: Fn(P::Assoc) -> Parser<P2>>(_: Parser<P>, _: F) -> Parser<Bind<P, F>>
    { loop {} }

fn main() {
    if_impl().0;
}
```


### 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.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-pc-windows-msvc
release: 1.81.0
LLVM version: 18.1.7
```

Both nightly and beta versions produced the same result as stable (as far as I can tell).

### Error output

```
error[E0658]: `impl Trait` in type aliases is unstable                                                                                                                                                                                 
 --> src/main.rs:3:28
  |
3 |     pub type OpaqueBlock = impl Trait;
  |                            ^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information

error[E0658]: `impl Trait` in type aliases is unstable
 --> src/main.rs:4:25
  |
4 |     pub type OpaqueIf = impl Trait;
  |                         ^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information

error: unconstrained opaque type                                                                                                                                                                                                       
 --> src/main.rs:3:28
  |
3 |     pub type OpaqueBlock = impl Trait;
  |                            ^^^^^^^^^^
  |
  = note: `OpaqueBlock` must be used in combination with a concrete type within the same module

error: internal compiler error: compiler\rustc_middle\src\ty\normalize_erasing_regions.rs:168:90: Failed to normalize Alias(Opaque, AliasTy { args: [], def_id: DefId(0:46 ~ rustc_hang[6e18]::impl_trait_mod::OpaqueIf::{opaque#0}) }), maybe try to call `try_normalize_erasing_regions` instead

[...backtrace...]

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.81.0 (eeb90cda1 2024-09-04) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0658`.
error: could not compile `rustc-hang` (bin "rustc-hang") due to 3 previous errors
```

<!--
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>

```
thread 'rustc' panicked at compiler\rustc_middle\src\ty\normalize_erasing_regions.rs:168:90:
Box<dyn Any>
stack backtrace:
   0:     0x7ff880eb408d - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ff880eb408d - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff880eb408d - std::sys::backtrace::_print_fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:65
   3:     0x7ff880eb408d - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:40
   4:     0x7ff880ee4bb9 - core::fmt::rt::Argument::fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\rt.rs:173
   5:     0x7ff880ee4bb9 - core::fmt::write
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\mod.rs:1182
   6:     0x7ff880eaab71 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\io\mod.rs:1827
   7:     0x7ff880eb7127 - std::panicking::default_hook::closure$1
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:269
   8:     0x7ff880eb6d19 - std::panicking::default_hook
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:296
   9:     0x7ff8770d2ed5 - memchr
  10:     0x7ff880eb796b - alloc::boxed::impl$50::call
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\alloc\src\boxed.rs:2084
  11:     0x7ff880eb796b - std::panicking::rust_panic_with_hook
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:808
  12:     0x7ff8786c0ea3 - <rustc_hir_pretty[ded6b9e63cf9049a]::State>::print_variant
  13:     0x7ff8786b34f9 - <rustc_hir_pretty[ded6b9e63cf9049a]::State>::print_variant
  14:     0x7ff8786acad9 - <rustc_hir_pretty[ded6b9e63cf9049a]::State>::print_variant
  15:     0x7ff8786cd105 - <rustc_errors[cac40cfc73911857]::diagnostic::BugAbort as rustc_errors[cac40cfc73911857]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  16:     0x7ff8785de6a2 - rustc_middle[1ecd3c849d31efbc]::util::bug::bug_fmt
  17:     0x7ff8785bea6d - rustc_middle[1ecd3c849d31efbc]::ty::consts::const_param_default
  18:     0x7ff8785be8ad - rustc_middle[1ecd3c849d31efbc]::ty::consts::const_param_default
  19:     0x7ff8785de5a2 - rustc_middle[1ecd3c849d31efbc]::util::bug::bug_fmt
  20:     0x7ff876f0b9f1 - <rustc_middle[1ecd3c849d31efbc]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir[4ff8edeed296e029]::fold::TypeFolder<rustc_middle[1ecd3c849d31efbc]::ty::context::TyCtxt>>::fold_ty
  21:     0x7ff876007a71 - rustc_monomorphize[9337c2a47ab967d8]::polymorphize::unused_generic_params
  22:     0x7ff87610283f - <rustc_mir_transform[9cb31845a5a5293]::elaborate_drops::ElaborateDrops as rustc_middle[1ecd3c849d31efbc]::mir::MirPass>::run_pass
  23:     0x7ff87602a36c - <rustc_mir_transform[9cb31845a5a5293]::simplify::SimplifyCfg as rustc_middle[1ecd3c849d31efbc]::mir::MirPass>::run_pass
  24:     0x7ff8760e7965 - rustc_mir_transform[9cb31845a5a5293]::mir_drops_elaborated_and_const_checked
  25:     0x7ff87674ea7b - rustc_query_impl[6b8c53a45d99a773]::plumbing::query_key_hash_verify_all
  26:     0x7ff87669ac49 - rustc_ty_utils[3966f556ce2470bb]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  27:     0x7ff876752e7b - rustc_query_impl[6b8c53a45d99a773]::plumbing::query_key_hash_verify_all
  28:     0x7ff875c89c15 - rustc_interface[ce19ee65e5c643b1]::passes::analysis
  29:     0x7ff875881e4b - rustc_ty_utils[3966f556ce2470bb]::ty::adt_sized_constraint
  30:     0x7ff8757f3ea5 - rustc_ty_utils[3966f556ce2470bb]::ty::adt_sized_constraint
  31:     0x7ff87588a9f3 - rustc_query_impl[6b8c53a45d99a773]::query_system
  32:     0x7ff872ee6a70 - _wpgmptr
  33:     0x7ff872ee2e66 - _wpgmptr
  34:     0x7ff872eec1ab - _wpgmptr
  35:     0x7ff880ec8f0d - alloc::boxed::impl$48::call_once
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\alloc\src\boxed.rs:2070
  36:     0x7ff880ec8f0d - alloc::boxed::impl$48::call_once
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\alloc\src\boxed.rs:2070
  37:     0x7ff880ec8f0d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\pal\windows\thread.rs:58
  38:     0x7ff8f5d97374 - BaseThreadInitThunk
  39:     0x7ff8f733cc91 - RtlUserThreadStart
```

</p>
</details>

Related to
https://github.com/rust-lang/rust/issues/127353 also produces an ICE on stable using features which are supposed to be locked behind `type_alias_impl_trait`.