Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE in mir_drops_elaborated_and_const_checked #135039

Open
veluca93 opened this issue Jan 2, 2025 · 5 comments
Open

ICE in mir_drops_elaborated_and_const_checked #135039

veluca93 opened this issue Jan 2, 2025 · 5 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@veluca93
Copy link
Contributor

veluca93 commented Jan 2, 2025

Code

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

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

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>

@veluca93 veluca93 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 2, 2025
@veluca93
Copy link
Contributor Author

veluca93 commented Jan 2, 2025

A bit more investigation (with some help from @sarah-quinones) led me to this additional, possibly related ICE:

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> {                                         
    data: Option<UserId<Backend>>,                                                      
}

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

pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}

ICE + backtrace:

error: internal compiler error: error performing operation: fully_perform
  |
  = note: delayed at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:87:25
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
             2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
             3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
             4: <rustc_middle::ty::ParamEnvAnd<rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives> as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform
             5: rustc_borrowck::type_check::liveness::trace::trace
             6: rustc_borrowck::type_check::type_check
             7: rustc_borrowck::nll::compute_regions
             8: rustc_borrowck::do_mir_borrowck
             9: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            11: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
            12: rustc_interface::passes::run_required_analyses
            13: rustc_interface::passes::analysis
            14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            16: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            17: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
            18: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            19: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            20: std::sys::pal::unix::thread::Thread::new::thread_start
            21: <unknown>
            22: <unknown>

Note that this example does not use async.

@compiler-errors
Copy link
Member

Just noting that is not "minimized", since that second ICE is a totally different ICE from the first.

@veluca93
Copy link
Contributor Author

veluca93 commented Jan 2, 2025

Just noting that is not "minimized", since that second ICE is a totally different ICE from the first.

Good point, changed the wording (it might make sense to open a second issue, WDYT?)

@veluca93
Copy link
Contributor Author

veluca93 commented Jan 2, 2025

One more bit of information: the code is not supposed to compile (it is missing a Authz: AuthUser bound), which is something I missed when writing the code originally.

@lqd
Copy link
Member

lqd commented Jan 2, 2025

You don't need to change the code to get the two different ICEs, just cargo check the OP to get the second one.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants