Repository: rust
Issue: [ICE]:  maybe try to call `try_normalize_erasing_regions` instead
Labels: I-ICE,T-compiler,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
use std::hint::black_box;
trait Func {
    type Ret: Id;
}
trait Id {
    type Assoc;
}
fn main() {}
impl Id for i32 {
    type Assoc = i32;
}
impl<F: FnOnce() -> R, R: Id> Func for F {
    type Ret = R;
}
fn bar() -> impl Copy + Id {
    0u32
}
struct Foo<T: Func> {
    _func: T,
    value: Option<<<T as Func>::Ret as Id>::Assoc>,
}
fn main() {
    let mut fn_def = black_box(Foo {
        _func: bar,
        value: None,
    });
    let fn_ptr = black_box(Foo {
        _func: bar as fn() -> _,
        value: None,
    });
    fn_def.value = fn_ptr.value;
    black_box(fn_def);
}

```


### 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.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3
```

### Error output

```
error[E0428]: the name `main` is defined multiple times
  --> mutant.rs:22:1
   |
8  | fn main() {}
   | --------- previous definition of the value `main` here
...
22 | fn main() {
   | ^^^^^^^^^ `main` redefined here
   |
   = note: `main` must be defined only once in the value namespace of this module

error[E0277]: the trait bound `u32: Id` is not satisfied
  --> mutant.rs:15:13
   |
15 | fn bar() -> impl Copy + Id {
   |             ^^^^^^^^^^^^^^ the trait `Id` is not implemented for `u32`
16 |     0u32
   |     ---- return type was inferred to be `u32` here
   |
   = help: the trait `Id` is implemented for `i32`

error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:90: Failed to normalize std::option::Option<Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [FnDef(DefId(0:15 ~ mutant[20f1]::bar), [])], def_id: DefId(0:5 ~ mutant[20f1]::Func::Ret), .. })], def_id: DefId(0:7 ~ mutant[20f1]::Id::Assoc), .. })>, maybe try to call `try_normalize_erasing_regions` instead

thread 'rustc' panicked at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:90:
Box<dyn Any>
stack backtrace:
...
note: compiler flags: --crate-type staticlib -C link-dead-code -C debuginfo=2 -C opt-level=3 -Z mir-opt-level=3

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
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0428.
For more information about an error, try `rustc --explain E0277`.
```

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

```
stack backtrace:
   0:     0x7fde3585517a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hfadad24fb33e3d1a
   1:     0x7fde360040a6 - core::fmt::write::h42d25fbda60cd99f
   2:     0x7fde373c3351 - std::io::Write::write_fmt::hc2819193e80b365e
   3:     0x7fde35854fd2 - std::sys::backtrace::BacktraceLock::print::h9450230402d77664
   4:     0x7fde358574d6 - std::panicking::default_hook::{{closure}}::h739047d4d787c596
   5:     0x7fde35857320 - std::panicking::default_hook::h203d1229480f37a5
   6:     0x7fde348d2269 - std[56fe22ad9ea837fd]::panicking::update_hook::<alloc[b5641001d343df5f]::boxed::Box<rustc_driver_impl[945e9afaf49c7d35]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7fde35857be8 - std::panicking::rust_panic_with_hook::h657fdcc17f7e2546
   8:     0x7fde3490c191 - std[56fe22ad9ea837fd]::panicking::begin_panic::<rustc_errors[43c84716ac990581]::ExplicitBug>::{closure#0}
   9:     0x7fde348ff166 - std[56fe22ad9ea837fd]::sys::backtrace::__rust_end_short_backtrace::<std[56fe22ad9ea837fd]::panicking::begin_panic<rustc_errors[43c84716ac990581]::ExplicitBug>::{closure#0}, !>
  10:     0x7fde348feefe - std[56fe22ad9ea837fd]::panicking::begin_panic::<rustc_errors[43c84716ac990581]::ExplicitBug>
  11:     0x7fde34915e71 - <rustc_errors[43c84716ac990581]::diagnostic::BugAbort as rustc_errors[43c84716ac990581]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7fde34f8f2c3 - rustc_middle[f0eb6ba890d0a9bb]::util::bug::opt_span_bug_fmt::<rustc_span[db86d96c2ae2e3a4]::span_encoding::Span>::{closure#0}
  13:     0x7fde34f758ba - rustc_middle[f0eb6ba890d0a9bb]::ty::context::tls::with_opt::<rustc_middle[f0eb6ba890d0a9bb]::util::bug::opt_span_bug_fmt<rustc_span[db86d96c2ae2e3a4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fde34f7574b - rustc_middle[f0eb6ba890d0a9bb]::ty::context::tls::with_context_opt::<rustc_middle[f0eb6ba890d0a9bb]::ty::context::tls::with_opt<rustc_middle[f0eb6ba890d0a9bb]::util::bug::opt_span_bug_fmt<rustc_span[db86d96c2ae2e3a4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fde331e7300 - rustc_middle[f0eb6ba890d0a9bb]::util::bug::bug_fmt
  16:     0x7fde368f39bc - <rustc_middle[f0eb6ba890d0a9bb]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir[8408d34320f8a6fb]::fold::TypeFolder<rustc_middle[f0eb6ba890d0a9bb]::ty::context::TyCtxt>>::fold_ty
  17:     0x7fde3643e8af - <rustc_mir_dataflow[d330eec8ae5b9552]::elaborate_drops::DropCtxt<rustc_mir_transform[c62e463fc59f8bd1]::elaborate_drops::ElaborateDropsCtxt>>::elaborate_drop
  18:     0x7fde32a290dd - <rustc_mir_transform[c62e463fc59f8bd1]::elaborate_drops::ElaborateDrops as rustc_mir_transform[c62e463fc59f8bd1]::pass_manager::MirPass>::run_pass
  19:     0x7fde36009348 - rustc_mir_transform[c62e463fc59f8bd1]::run_analysis_to_runtime_passes
  20:     0x7fde362ddb58 - rustc_mir_transform[c62e463fc59f8bd1]::mir_drops_elaborated_and_const_checked
  21:     0x7fde362dd45b - rustc_query_impl[1357963d8dd30e8b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1357963d8dd30e8b]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f0eb6ba890d0a9bb]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7fde36723681 - rustc_query_system[887bb79932b1d8c1]::query::plumbing::try_execute_query::<rustc_query_impl[1357963d8dd30e8b]::DynamicConfig<rustc_query_system[887bb79932b1d8c1]::query::caches::VecCache<rustc_span[db86d96c2ae2e3a4]::def_id::LocalDefId, rustc_middle[f0eb6ba890d0a9bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1357963d8dd30e8b]::plumbing::QueryCtxt, false>
  23:     0x7fde367230cd - rustc_query_impl[1357963d8dd30e8b]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7fde36869488 - rustc_interface[5fea8bf9cd0b71b5]::passes::run_required_analyses
  25:     0x7fde36e0861e - rustc_interface[5fea8bf9cd0b71b5]::passes::analysis
  26:     0x7fde36e085ef - rustc_query_impl[1357963d8dd30e8b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1357963d8dd30e8b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f0eb6ba890d0a9bb]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7fde36f92cee - rustc_query_system[887bb79932b1d8c1]::query::plumbing::try_execute_query::<rustc_query_impl[1357963d8dd30e8b]::DynamicConfig<rustc_query_system[887bb79932b1d8c1]::query::caches::SingleCache<rustc_middle[f0eb6ba890d0a9bb]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1357963d8dd30e8b]::plumbing::QueryCtxt, false>
  28:     0x7fde36f929ce - rustc_query_impl[1357963d8dd30e8b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7fde36e8707a - rustc_interface[5fea8bf9cd0b71b5]::interface::run_compiler::<core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>, rustc_driver_impl[945e9afaf49c7d35]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7fde36ecd5d0 - std[56fe22ad9ea837fd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5fea8bf9cd0b71b5]::util::run_in_thread_with_globals<rustc_interface[5fea8bf9cd0b71b5]::util::run_in_thread_pool_with_globals<rustc_interface[5fea8bf9cd0b71b5]::interface::run_compiler<core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>, rustc_driver_impl[945e9afaf49c7d35]::run_compiler::{closure#0}>::{closure#1}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>::{closure#0}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>
  31:     0x7fde36ecd9eb - <<std[56fe22ad9ea837fd]::thread::Builder>::spawn_unchecked_<rustc_interface[5fea8bf9cd0b71b5]::util::run_in_thread_with_globals<rustc_interface[5fea8bf9cd0b71b5]::util::run_in_thread_pool_with_globals<rustc_interface[5fea8bf9cd0b71b5]::interface::run_compiler<core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>, rustc_driver_impl[945e9afaf49c7d35]::run_compiler::{closure#0}>::{closure#1}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>::{closure#0}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5ba82ee3405aa490]::result::Result<(), rustc_span[db86d96c2ae2e3a4]::ErrorGuaranteed>>::{closure#1} as core[5ba82ee3405aa490]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7fde36ece4b9 - std::sys::pal::unix::thread::Thread::new::thread_start::hb3d6392adeea417c
  33:     0x7fde3106bac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  34:     0x7fde310fd850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  35:                0x0 - <unknown>
```

</p>
</details>

### Anything else

Could this be related to https://github.com/rust-lang/rust/issues/120267?