Skip to content

ICE when using a macro to wrap a function in multiple arms of match statement #16678

@Person-93

Description

@Person-93

Summary

macro_rules! wrap_fn {
  () => {{
    fn wrapper(_arg: ()) {
      unsafe { f(_arg) }
    }
    wrapper
  }};
}

pub fn run() {
  let _wrapped_fn = match true {
    true => wrap_fn!(),
    false => wrap_fn!(),
  };
}

unsafe fn f(_arg: ()) {
  loop {}
}

Version

rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0
LLVM version: 21.1.8

Error output

error: internal compiler error: /rustc-dev/4a4ef493e3a1488c6e321570238084b38948f6db/compiler/rustc_middle/src/ty/typeck_results.rs:590:9: node HirId(DefId(0:6 ~ clippy_bug[662f]::run::wrapper).9) (expr `_arg`) cannot be placed in TypeckResults with hir_owner DefId(0:4 ~ clippy_bug[662f]::run)


thread 'rustc' (279887) panicked at /rustc-dev/4a4ef493e3a1488c6e321570238084b38948f6db/compiler/rustc_middle/src/ty/typeck_results.rs:590:9:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results::{closure#0}
   7: rustc_middle::ty::context::tls::with::<rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results::{closure#0}, !>::{closure#0}
   8: rustc_middle::ty::context::tls::with_context::<rustc_middle::ty::context::tls::with<rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results::{closure#0}, !>::{closure#0}, !>::{closure#0}
   9: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_context<rustc_middle::ty::context::tls::with<rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results::{closure#0}, !>::{closure#0}, !>::{closure#0}, !>
  10: rustc_middle::ty::context::tls::with::<rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results::{closure#0}, !>
  11: rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results
  12: <rustc_middle::ty::typeck_results::TypeckResults>::expr_ty
  13: clippy_lints::matches::match_same_arms::check::{closure#4}::{closure#0}::{closure#0}
  14: <clippy_utils::hir_utils::HirEqInterExpr>::eq_expr
  15: <clippy_utils::hir_utils::HirEqInterExpr>::eq_expr
  16: <clippy_utils::hir_utils::HirEqInterExpr>::eq_block
  17: <clippy_utils::hir_utils::HirEqInterExpr>::eq_expr
  18: <clippy_utils::hir_utils::HirEqInterExpr>::eq_block
  19: <clippy_utils::hir_utils::HirEqInterExpr>::eq_expr
  20: <clippy_utils::hir_utils::HirEqInterExpr>::eq_body
  21: <clippy_utils::hir_utils::HirEqInterExpr>::eq_item
  22: <clippy_utils::hir_utils::HirEqInterExpr>::eq_block
  23: <clippy_utils::hir_utils::HirEqInterExpr>::eq_expr
  24: clippy_lints::matches::match_same_arms::check::{closure#4}::{closure#0}
  25: clippy_lints::matches::match_same_arms::check
  26: <clippy_lints::matches::Matches as rustc_lint::passes::LateLintPass>::check_expr
  27: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
  28: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr
  29: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_block
  30: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
  31: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr
  32: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_body
  33: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_fn
  34: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
  35: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass>>::process_mod
  36: rustc_lint::late::check_crate::{closure#0}
  37: rustc_lint::late::check_crate
  38: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  39: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  40: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: rustc 1.94.0 (4a4ef493e 2026-03-02) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=mold

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

query stack during panic:
#0 [analysis] running analysis passes on crate `clippy_bug`
end of query stack
note: Clippy version: clippy 0.1.94 (4a4ef493e3 2026-03-02)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

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