Repository: rust
Issue: ICE in mir_drops_elaborated_and_const_checked
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
pub type UserId<Backend> = <<Backend as AuthnBackend>::User as AuthUser>::Id;

pub trait AuthUser {
    type Id;
}

pub trait AuthnBackend {
    type User: AuthUser;
}

pub struct AuthSession<Backend: AuthnBackend> {
    user: Option<Backend::User>,
    data: Option<UserId<Backend>>,
}

pub trait Authz: Sized {
    type AuthnBackend: AuthnBackend<User = Self>;
}

pub trait Query<User: Authz> {
    type Output;
    async fn run(&self) -> Result<Self::Output, ()>;
}

pub async fn run_query<User: Authz, Q: Query<User> + 'static>(
    auth: AuthSession<User::AuthnBackend>,
    query: Q,
) -> Result<Q::Output, ()> {
    let user = auth.user;
    query.run().await
}
```

(this is my best attempt at minimizing -- it includes some modified pieces from axum_login)


### 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.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1
```

The error appears to persist in the latest nightly (2025-01-01)

### Error output

```
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: [Alias(Projection, AliasTy { args: [User/#0], def_id: DefId(0:14 ~ lib[8f96]::Authz::AuthnBackend), .. })], def_id: DefId(0:8 ~ lib[8f96]::AuthnBackend::User), .. })], def_id: DefId(0:6 ~ lib[8f96]::AuthUser::Id), .. })>, 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>
```

<!--
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:     0x79bade44012a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h5b6bd5631a6d1f6b
   1:     0x79badec218f8 - core::fmt::write::h7550c97b06c86515
   2:     0x79badfe58b91 - std::io::Write::write_fmt::h7b09c64fe0be9c84
   3:     0x79bade43ff82 - std::sys::backtrace::BacktraceLock::print::h2395ccd2c84ba3aa
   4:     0x79bade442456 - std::panicking::default_hook::{{closure}}::he19d4c7230e07961
   5:     0x79bade4422a0 - std::panicking::default_hook::hf614597d3c67bbdb
   6:     0x79badd504556 - std[c6eb78587944e35c]::panicking::update_hook::<alloc[148a978a4a62f5d]::boxed::Box<rustc_driver_impl[4c2d2ad79fb810ac]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x79bade442b68 - std::panicking::rust_panic_with_hook::h8942133a8b252070
   8:     0x79badd53b371 - std[c6eb78587944e35c]::panicking::begin_panic::<rustc_errors[7f4c80274b6ccf5]::ExplicitBug>::{closure#0}
   9:     0x79badd52e976 - std[c6eb78587944e35c]::sys::backtrace::__rust_end_short_backtrace::<std[c6eb78587944e35c]::panicking::begin_panic<rustc_errors[7f4c80274b6ccf5]::ExplicitBug>::{closure#0}, !>
  10:     0x79badd52e933 - std[c6eb78587944e35c]::panicking::begin_panic::<rustc_errors[7f4c80274b6ccf5]::ExplicitBug>
  11:     0x79badd544a31 - <rustc_errors[7f4c80274b6ccf5]::diagnostic::BugAbort as rustc_errors[7f4c80274b6ccf5]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x79baddb6ee74 - rustc_middle[a886f61dbc61428a]::util::bug::opt_span_bug_fmt::<rustc_span[3e5cf3424d44936d]::span_encoding::Span>::{closure#0}
  13:     0x79baddb54f6a - rustc_middle[a886f61dbc61428a]::ty::context::tls::with_opt::<rustc_middle[a886f61dbc61428a]::util::bug::opt_span_bug_fmt<rustc_span[3e5cf3424d44936d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x79baddb54dfb - rustc_middle[a886f61dbc61428a]::ty::context::tls::with_context_opt::<rustc_middle[a886f61dbc61428a]::ty::context::tls::with_opt<rustc_middle[a886f61dbc61428a]::util::bug::opt_span_bug_fmt<rustc_span[3e5cf3424d44936d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x79badc4839a0 - rustc_middle[a886f61dbc61428a]::util::bug::bug_fmt
  16:     0x79badf2e7f70 - <rustc_middle[a886f61dbc61428a]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir[953d4871ec2d6eb6]::fold::TypeFolder<rustc_middle[a886f61dbc61428a]::ty::context::TyCtxt>>::fold_ty
  17:     0x79badf4fe25d - <rustc_mir_dataflow[9c27b51dffa9535c]::elaborate_drops::DropCtxt<rustc_mir_transform[b36c87ceb4bb9a8e]::elaborate_drops::ElaborateDropsCtxt>>::elaborate_drop
  18:     0x79badbc5ea22 - <rustc_mir_transform[b36c87ceb4bb9a8e]::elaborate_drops::ElaborateDrops as rustc_mir_transform[b36c87ceb4bb9a8e]::pass_manager::MirPass>::run_pass
  19:     0x79badec066b9 - rustc_mir_transform[b36c87ceb4bb9a8e]::run_analysis_to_runtime_passes
  20:     0x79badedf62de - rustc_mir_transform[b36c87ceb4bb9a8e]::mir_drops_elaborated_and_const_checked
  21:     0x79badedf5cfd - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  22:     0x79badeef3e68 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  23:     0x79badeef36cd - rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  24:     0x79badf10af19 - rustc_mir_transform[b36c87ceb4bb9a8e]::optimized_mir
  25:     0x79badf108369 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  26:     0x79badec24b2d - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::DefIdCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  27:     0x79badec241b3 - rustc_query_impl[db795c774d495014]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  28:     0x79badf6ce39f - rustc_middle[a886f61dbc61428a]::query::plumbing::query_get_at::<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::DefIdCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>>
  29:     0x79baddb6e8b5 - <rustc_middle[a886f61dbc61428a]::ty::context::TyCtxt>::coroutine_layout
  30:     0x79badf273c28 - rustc_ty_utils[45bf0f8bee683616]::layout::layout_of_uncached
  31:     0x79badf264a46 - rustc_ty_utils[45bf0f8bee683616]::layout::layout_of
  32:     0x79badf2649d1 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>
  33:     0x79badf2640b2 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::DefaultCache<rustc_middle[a886f61dbc61428a]::ty::ParamEnvAnd<rustc_middle[a886f61dbc61428a]::ty::Ty>, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  34:     0x79badf263da9 - rustc_query_impl[db795c774d495014]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  35:     0x79badc2130da - <rustc_mir_transform[b36c87ceb4bb9a8e]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[b36c87ceb4bb9a8e]::pass_manager::MirLint>::run_lint
  36:     0x79badec066b9 - rustc_mir_transform[b36c87ceb4bb9a8e]::run_analysis_to_runtime_passes
  37:     0x79badedf62de - rustc_mir_transform[b36c87ceb4bb9a8e]::mir_drops_elaborated_and_const_checked
  38:     0x79badedf5cfd - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  39:     0x79badeef3e68 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  40:     0x79badeef36cd - rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  41:     0x79badf4f0705 - rustc_interface[88a02114bbdb2383]::passes::run_required_analyses
  42:     0x79badf4e72e5 - rustc_interface[88a02114bbdb2383]::passes::analysis
  43:     0x79badf4e72c9 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>
  44:     0x79badf9f2662 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::SingleCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  45:     0x79badf9f238f - rustc_query_impl[db795c774d495014]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x79badf9620bb - rustc_interface[88a02114bbdb2383]::interface::run_compiler::<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}
  47:     0x79badf9533d9 - std[c6eb78587944e35c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>
  48:     0x79badfa22fac - <<std[c6eb78587944e35c]::thread::Builder>::spawn_unchecked_<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#1} as core[c06ff78fa456ca03]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x79badfa23a6b - std::sys::pal::unix::thread::Thread::new::thread_start::hcc78f3943333fa94
  50:     0x79bad9ea339d - <unknown>
  51:     0x79bad9f2849c - <unknown>
  52:                0x0 - <unknown>
```

</p>
</details>