Skip to content

[ICE]: Drop location span error: need to handle more ItemKind #156288

@matthiaskrgr

Description

@matthiaskrgr

snippet:

#[warn(rust_2021_incompatible_closure_captures)]
enum Functions {
    Square = |b| move || format!("{b}"),
}

Version information

rustc 1.97.0-nightly (ffccab6ab 2026-05-07)
binary: rustc
commit-hash: ffccab6abef68b70c5e23cfbfb1ac7680104040d
commit-date: 2026-05-07
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Possibly related line of code:

let owner_node = tcx.hir_node(owner_id);
let owner_span = match owner_node {
hir::Node::Item(item) => match item.kind {
hir::ItemKind::Fn { body: owner_id, .. } => tcx.hir_span(owner_id.hir_id),
_ => {
bug!("Drop location span error: need to handle more ItemKind '{:?}'", item.kind);
}
},
hir::Node::Block(block) => tcx.hir_span(block.hir_id),
hir::Node::TraitItem(item) => tcx.hir_span(item.hir_id()),
hir::Node::ImplItem(item) => tcx.hir_span(item.hir_id()),
_ => {

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:4:2
  |
4 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:3:14
  |
3 |     Square = |b| move || format!("{b}"),
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found closure
  |
  = note: expected type `isize`
          found closure `{closure@/tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:3:14: 3:17}`
  = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr`

error: internal compiler error: /rustc-dev/ffccab6abef68b70c5e23cfbfb1ac7680104040d/compiler/rustc_hir_typeck/src/upvar.rs:2033:17: Drop location span error: need to handle more ItemKind 'Enum(Functions#0, Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:2:15: 2:15 (#0), span: /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:2:15: 2:15 (#0) }, EnumDef { variants: [Variant { ident: Square#0, hir_id: HirId(DefId(0:3 ~ mvce[c1d7]::Functions).1), def_id: DefId(0:4 ~ mvce[c1d7]::Functions::Square), data: Unit(HirId(DefId(0:3 ~ mvce[c1d7]::Functions).2), DefId(0:5 ~ mvce[c1d7]::Functions::Square::{constructor#0})), disr_expr: Some(AnonConst { hir_id: HirId(DefId(0:3 ~ mvce[c1d7]::Functions).3), def_id: DefId(0:6 ~ mvce[c1d7]::Functions::Square::{constant#0}), body: BodyId { hir_id: HirId(DefId(0:3 ~ mvce[c1d7]::Functions).4) }, span: /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:3:14: 3:40 (#0) }), span: /tmp/icemaker_global_tempdir.rSwPHBGG7I2G/rustc_testrunner_tmpdir_reporting.Ydg425y9hOKB/mvce.rs:3:5: 3:40 (#0) }] })'


thread 'rustc' (3470898) panicked at /rustc-dev/ffccab6abef68b70c5e23cfbfb1ac7680104040d/compiler/rustc_hir_typeck/src/upvar.rs:2033:17:
Box<dyn Any>
stack backtrace:
   0:     0x7ff8b2c65859 - <<std[b44b2a9af91b8814]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[5fd9be8f539cadc0]::fmt::Display>::fmt
   1:     0x7ff8b321b748 - core[5fd9be8f539cadc0]::fmt::write
   2:     0x7ff8b2c7c286 - <std[b44b2a9af91b8814]::sys::stdio::unix::Stderr as std[b44b2a9af91b8814]::io::Write>::write_fmt
   3:     0x7ff8b2c3b8fe - std[b44b2a9af91b8814]::panicking::default_hook::{closure#0}
   4:     0x7ff8b2c58f13 - std[b44b2a9af91b8814]::panicking::default_hook
   5:     0x7ff8b1b4a431 - std[b44b2a9af91b8814]::panicking::update_hook::<alloc[52580bf504f902c0]::boxed::Box<rustc_driver_impl[b097e61246baddd0]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ff8b2c591f2 - std[b44b2a9af91b8814]::panicking::panic_with_hook
   7:     0x7ff8b1b77e91 - std[b44b2a9af91b8814]::panicking::begin_panic::<rustc_errors[7dc0ae575d2f60e7]::ExplicitBug>::{closure#0}
   8:     0x7ff8b1b70e86 - std[b44b2a9af91b8814]::sys::backtrace::__rust_end_short_backtrace::<std[b44b2a9af91b8814]::panicking::begin_panic<rustc_errors[7dc0ae575d2f60e7]::ExplicitBug>::{closure#0}, !>
   9:     0x7ff8b1b70beb - std[b44b2a9af91b8814]::panicking::begin_panic::<rustc_errors[7dc0ae575d2f60e7]::ExplicitBug>
  10:     0x7ff8b1b83371 - <rustc_errors[7dc0ae575d2f60e7]::diagnostic::BugAbort as rustc_errors[7dc0ae575d2f60e7]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7ff8b21908f9 - rustc_middle[a2cb8ab9f4e9488e]::util::bug::opt_span_bug_fmt::<rustc_span[d4e956e734626f0]::span_encoding::Span>::{closure#0}
  12:     0x7ff8b2190a62 - rustc_middle[a2cb8ab9f4e9488e]::ty::context::tls::with_opt::<rustc_middle[a2cb8ab9f4e9488e]::util::bug::opt_span_bug_fmt<rustc_span[d4e956e734626f0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7ff8b217f6cb - rustc_middle[a2cb8ab9f4e9488e]::ty::context::tls::with_context_opt::<rustc_middle[a2cb8ab9f4e9488e]::ty::context::tls::with_opt<rustc_middle[a2cb8ab9f4e9488e]::util::bug::opt_span_bug_fmt<rustc_span[d4e956e734626f0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7ff8afb61b24 - rustc_middle[a2cb8ab9f4e9488e]::util::bug::bug_fmt
  15:     0x7ff8b1ed4e5b - <<rustc_hir_typeck[2b956b128d2333ae]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis::MigrationLint as rustc_errors[7dc0ae575d2f60e7]::diagnostic::Diagnostic<()>>::into_diag
  16:     0x7ff8b1e2c280 - <rustc_middle[a2cb8ab9f4e9488e]::lint::emit_lint_base<<rustc_hir_typeck[2b956b128d2333ae]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis::MigrationLint>::{closure#0} as core[5fd9be8f539cadc0]::ops::function::FnOnce<(rustc_errors[7dc0ae575d2f60e7]::DiagCtxtHandle, rustc_errors[7dc0ae575d2f60e7]::Level)>>::call_once::{shim:vtable#0}
  17:     0x7ff8b3b143a8 - rustc_middle[a2cb8ab9f4e9488e]::lint::emit_lint_base::emit_lint_base_impl
  18:     0x7ff8b1e7be12 - <rustc_hir_typeck[2b956b128d2333ae]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis
  19:     0x7ff8b3f7733f - <rustc_hir_typeck[2b956b128d2333ae]::fn_ctxt::FnCtxt>::analyze_closure
  20:     0x7ff8b3c00ee6 - <rustc_hir_typeck[2b956b128d2333ae]::upvar::InferBorrowKindVisitor as rustc_hir[882fa584cdcb0b15]::intravisit::Visitor>::visit_expr
  21:     0x7ff8b3c00ebf - <rustc_hir_typeck[2b956b128d2333ae]::upvar::InferBorrowKindVisitor as rustc_hir[882fa584cdcb0b15]::intravisit::Visitor>::visit_expr
  22:     0x7ff8b3c056ec - rustc_hir_typeck[2b956b128d2333ae]::typeck_with_inspect::{closure#0}
  23:     0x7ff8b3c02130 - rustc_query_impl[469555595b0d02a6]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  24:     0x7ff8b336a3a6 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_data_structures[fddbf0b6d549df5f]::vec_cache::VecCache<rustc_span[d4e956e734626f0]::def_id::LocalDefId, rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[a2cb8ab9f4e9488e]::dep_graph::graph::DepNodeIndex>, false>
  25:     0x7ff8b3369bc3 - rustc_query_impl[469555595b0d02a6]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7ff8b3a9dd7f - rustc_mir_build[b776ca64a679a545]::thir::pattern::check_match::check_match
  27:     0x7ff8b3a9d1c7 - rustc_query_impl[469555595b0d02a6]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  28:     0x7ff8b3cc5472 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_data_structures[fddbf0b6d549df5f]::vec_cache::VecCache<rustc_span[d4e956e734626f0]::def_id::LocalDefId, rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[a2cb8ab9f4e9488e]::dep_graph::graph::DepNodeIndex>, false>
  29:     0x7ff8b3cc50ce - rustc_query_impl[469555595b0d02a6]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7ff8b3aa5249 - rustc_mir_build[b776ca64a679a545]::builder::build_mir_inner_impl
  31:     0x7ff8b320a72a - rustc_mir_transform[3f2ae7750aa2a0a1]::mir_built
  32:     0x7ff8b336a3a6 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_data_structures[fddbf0b6d549df5f]::vec_cache::VecCache<rustc_span[d4e956e734626f0]::def_id::LocalDefId, rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[a2cb8ab9f4e9488e]::dep_graph::graph::DepNodeIndex>, false>
  33:     0x7ff8b3369ec3 - rustc_query_impl[469555595b0d02a6]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  34:     0x7ff8b34eb805 - rustc_query_impl[469555595b0d02a6]::query_impl::trivial_const::invoke_provider_fn::__rust_begin_short_backtrace
  35:     0x7ff8b34eac98 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_middle[a2cb8ab9f4e9488e]::query::caches::DefIdCache<rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 32usize]>>, false>
  36:     0x7ff8b34ea310 - rustc_query_impl[469555595b0d02a6]::query_impl::trivial_const::execute_query_non_incr::__rust_end_short_backtrace
  37:     0x7ff8b3a32d3e - rustc_const_eval[6bde04882963fac7]::const_eval::eval_queries::eval_to_const_value_raw_provider
  38:     0x7ff8b3a32a96 - rustc_query_impl[469555595b0d02a6]::query_impl::eval_to_const_value_raw::invoke_provider_fn::__rust_begin_short_backtrace
  39:     0x7ff8b3a345d9 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_middle[a2cb8ab9f4e9488e]::query::caches::DefaultCache<rustc_middle[a2cb8ab9f4e9488e]::ty::PseudoCanonicalInput<rustc_middle[a2cb8ab9f4e9488e]::mir::interpret::GlobalId>, rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 24usize]>>, false>
  40:     0x7ff8b3a3417f - rustc_query_impl[469555595b0d02a6]::query_impl::eval_to_const_value_raw::execute_query_non_incr::__rust_end_short_backtrace
  41:     0x7ff8b3d4f581 - <rustc_middle[a2cb8ab9f4e9488e]::ty::context::TyCtxt>::const_eval_poly
  42:     0x7ff8b3d50ab7 - <rustc_middle[a2cb8ab9f4e9488e]::ty::adt::AdtDef>::eval_explicit_discr
  43:     0x7ff8b3ccf748 - rustc_hir_analysis[826b5ab2388147ec]::check::check::check_item_type
  44:     0x7ff8b3cc5ea6 - rustc_hir_analysis[826b5ab2388147ec]::check::wfcheck::check_well_formed
  45:     0x7ff8b3cc5e87 - rustc_query_impl[469555595b0d02a6]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  46:     0x7ff8b3cc5472 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_data_structures[fddbf0b6d549df5f]::vec_cache::VecCache<rustc_span[d4e956e734626f0]::def_id::LocalDefId, rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[a2cb8ab9f4e9488e]::dep_graph::graph::DepNodeIndex>, false>
  47:     0x7ff8b3cc5207 - rustc_query_impl[469555595b0d02a6]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  48:     0x7ff8b3cc15c0 - rustc_hir_analysis[826b5ab2388147ec]::check::wfcheck::check_type_wf
  49:     0x7ff8b3cc14d3 - rustc_query_impl[469555595b0d02a6]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  50:     0x7ff8b438eb90 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_middle[a2cb8ab9f4e9488e]::query::caches::SingleCache<rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 1usize]>>, false>
  51:     0x7ff8b438e969 - rustc_query_impl[469555595b0d02a6]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  52:     0x7ff8b3a9a623 - rustc_hir_analysis[826b5ab2388147ec]::check_crate
  53:     0x7ff8b336bae1 - rustc_interface[4f993990338980d2]::passes::analysis
  54:     0x7ff8b438dfc9 - rustc_query_impl[469555595b0d02a6]::execution::try_execute_query::<rustc_middle[a2cb8ab9f4e9488e]::query::caches::SingleCache<rustc_middle[a2cb8ab9f4e9488e]::query::erase::ErasedData<[u8; 0usize]>>, false>
  55:     0x7ff8b438dc33 - rustc_query_impl[469555595b0d02a6]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  56:     0x7ff8b43d181b - rustc_interface[4f993990338980d2]::interface::run_compiler::<(), rustc_driver_impl[b097e61246baddd0]::run_compiler::{closure#0}>::{closure#1}
  57:     0x7ff8b438187e - std[b44b2a9af91b8814]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4f993990338980d2]::util::run_in_thread_with_globals<rustc_interface[4f993990338980d2]::util::run_in_thread_pool_with_globals<rustc_interface[4f993990338980d2]::interface::run_compiler<(), rustc_driver_impl[b097e61246baddd0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  58:     0x7ff8b4381f6d - <std[b44b2a9af91b8814]::thread::lifecycle::spawn_unchecked<rustc_interface[4f993990338980d2]::util::run_in_thread_with_globals<rustc_interface[4f993990338980d2]::util::run_in_thread_pool_with_globals<rustc_interface[4f993990338980d2]::interface::run_compiler<(), rustc_driver_impl[b097e61246baddd0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5fd9be8f539cadc0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  59:     0x7ff8b4382d6c - <std[b44b2a9af91b8814]::sys::thread::unix::Thread>::new::thread_start
  60:     0x7ff8adea597a - <unknown>
  61:     0x7ff8adf292bc - <unknown>
  62:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.97.0-nightly (ffccab6ab 2026-05-07) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck_root] type-checking `Functions::Square::{constant#0}`
#1 [check_match] match-checking `Functions::Square::{constant#0}`
#2 [mir_built] building MIR for `Functions::Square::{constant#0}`
#3 [trivial_const] checking if `Functions::Square::{constant#0}` is a trivial const
#4 [eval_to_const_value_raw] simplifying constant for the type system `Functions::Square::{constant#0}`
#5 [check_well_formed] checking that `Functions` is well-formed
#6 [check_type_wf] checking that types are well-formed
#7 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️L-rust_2021_incompatible_closure_capturesLint: rust_2021_incompatible_closure_capturesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions