Skip to content

[ICE]: expected DefId to be a foreign function #153502

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct Foo(i32);

#[eii]
pub fn Foo(x: u64) {}

original:

struct Foo(i32);
impl Foo {
    pub fn dowork(&self) {
        println!("foo: doing work {}", self.0);
    }
}

impl Drop for Foo {
    fn drop(&mut self) {
        println!("foo: drop {}", self.0);
    }
}

#[eii]
pub fn Foo(x: u64) {}

fn main() {
    let x = Foo(1);
    let x = move || x.dowork();
    f(x);
}

Version information

rustc 1.96.0-nightly (f82485388 2026-03-06)
binary: rustc
commit-hash: f82485388963286763f8c8a9261ac227627f6a18
commit-date: 2026-03-06
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

};
let declaration_args = declaration.as_local().map(|def_id| {
if let Some(sig) = get_declaration_sig(tcx, def_id) {
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
} else {
panic!("expected {def_id:?} to be a foreign function");
}
});
match terr {
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => (
external_impl_args.nth(i).unwrap(),

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

Program output

error[E0658]: use of unstable library feature `extern_item_impls`
 --> /tmp/icemaker_global_tempdir.DRmNksf0uPkW/rustc_testrunner_tmpdir_reporting.QsbxgtRPlobI/mvce.rs:3:3
  |
3 | #[eii]
  |   ^^^
  |
  = note: see issue #125418 <https://github.com/rust-lang/rust/issues/125418> for more information
  = help: add `#![feature(extern_item_impls)]` to the crate attributes to enable
  = note: this compiler was built on 2026-03-06; consider upgrading it if it is out of date

error[E0428]: the name `Foo` is defined multiple times
 --> /tmp/icemaker_global_tempdir.DRmNksf0uPkW/rustc_testrunner_tmpdir_reporting.QsbxgtRPlobI/mvce.rs:4:1
  |
1 | struct Foo(i32);
  | ---------------- previous definition of the value `Foo` here
...
4 | pub fn Foo(x: u64) {}
  | ^^^^^^^^^^^^^^^^^^ `Foo` redefined here
  |
  = note: `Foo` must be defined only once in the value namespace of this module

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.DRmNksf0uPkW/rustc_testrunner_tmpdir_reporting.QsbxgtRPlobI/mvce.rs:4:22
  |
4 | pub fn Foo(x: u64) {}
  |                      ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.DRmNksf0uPkW/rustc_testrunner_tmpdir_reporting.QsbxgtRPlobI/mvce.rs`


thread 'rustc' (3632962) panicked at /rustc-dev/f82485388963286763f8c8a9261ac227627f6a18/compiler/rustc_hir_analysis/src/check/compare_eii.rs:423:13:
expected DefId(0:4 ~ mvce[d222]::Foo::{constructor#0}) to be a foreign function
stack backtrace:
   0:     0x7f2afc15df6b - <<std[1ac9ec7f151dc343]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[2185e438fa60127]::fmt::Display>::fmt
   1:     0x7f2afc822a08 - core[2185e438fa60127]::fmt::write
   2:     0x7f2afc174f76 - <std[1ac9ec7f151dc343]::sys::stdio::unix::Stderr as std[1ac9ec7f151dc343]::io::Write>::write_fmt
   3:     0x7f2afc134058 - std[1ac9ec7f151dc343]::panicking::default_hook::{closure#0}
   4:     0x7f2afc1513e3 - std[1ac9ec7f151dc343]::panicking::default_hook
   5:     0x7f2afb137e4c - std[1ac9ec7f151dc343]::panicking::update_hook::<alloc[1b3f84b8c09c25b1]::boxed::Box<rustc_driver_impl[6e789f234d303bfb]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f2afc1516c2 - std[1ac9ec7f151dc343]::panicking::panic_with_hook
   7:     0x7f2afc134118 - std[1ac9ec7f151dc343]::panicking::panic_handler::{closure#0}
   8:     0x7f2afc128669 - std[1ac9ec7f151dc343]::sys::backtrace::__rust_end_short_backtrace::<std[1ac9ec7f151dc343]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f2afc135b7d - __rustc[3c4f6ba47a7fa14c]::rust_begin_unwind
  10:     0x7f2af8d4543c - core[2185e438fa60127]::panicking::panic_fmt
  11:     0x7f2afb2e04f6 - rustc_hir_analysis[b1c64fc70d705e68]::check::compare_eii::compare_eii_function_types
  12:     0x7f2afd1d4098 - rustc_hir_analysis[b1c64fc70d705e68]::check::wfcheck::check_item_fn
  13:     0x7f2afd1a8dc8 - rustc_hir_analysis[b1c64fc70d705e68]::check::check::check_item_type
  14:     0x7f2afd1a5132 - rustc_hir_analysis[b1c64fc70d705e68]::check::wfcheck::check_well_formed
  15:     0x7f2afd1a5113 - rustc_query_impl[234cac1489f93c02]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f2afd1a46e5 - rustc_query_impl[234cac1489f93c02]::execution::try_execute_query::<rustc_data_structures[b1d728af8bd319df]::vec_cache::VecCache<rustc_span[bde3ed91d4975fd3]::def_id::LocalDefId, rustc_middle[6c1cd5853b8c3360]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[6c1cd5853b8c3360]::dep_graph::graph::DepNodeIndex>, false>
  17:     0x7f2afd1a4447 - rustc_query_impl[234cac1489f93c02]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f2afd1a134f - rustc_hir_analysis[b1c64fc70d705e68]::check::wfcheck::check_type_wf
  19:     0x7f2afd1a1259 - rustc_query_impl[234cac1489f93c02]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x7f2afda80b97 - rustc_query_impl[234cac1489f93c02]::execution::try_execute_query::<rustc_middle[6c1cd5853b8c3360]::query::caches::SingleCache<rustc_middle[6c1cd5853b8c3360]::query::erase::ErasedData<[u8; 1usize]>>, false>
  21:     0x7f2afda80969 - rustc_query_impl[234cac1489f93c02]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f2afd373e55 - rustc_hir_analysis[b1c64fc70d705e68]::check_crate
  23:     0x7f2afc8bc79d - rustc_interface[c926bcc183cff181]::passes::analysis
  24:     0x7f2afda82760 - rustc_query_impl[234cac1489f93c02]::execution::try_execute_query::<rustc_middle[6c1cd5853b8c3360]::query::caches::SingleCache<rustc_middle[6c1cd5853b8c3360]::query::erase::ErasedData<[u8; 0usize]>>, false>
  25:     0x7f2afda82447 - rustc_query_impl[234cac1489f93c02]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7f2afda3da6d - rustc_interface[c926bcc183cff181]::interface::run_compiler::<(), rustc_driver_impl[6e789f234d303bfb]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7f2afda6613e - std[1ac9ec7f151dc343]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c926bcc183cff181]::util::run_in_thread_with_globals<rustc_interface[c926bcc183cff181]::util::run_in_thread_pool_with_globals<rustc_interface[c926bcc183cff181]::interface::run_compiler<(), rustc_driver_impl[6e789f234d303bfb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f2afda669e0 - <std[1ac9ec7f151dc343]::thread::lifecycle::spawn_unchecked<rustc_interface[c926bcc183cff181]::util::run_in_thread_with_globals<rustc_interface[c926bcc183cff181]::util::run_in_thread_pool_with_globals<rustc_interface[c926bcc183cff181]::interface::run_compiler<(), rustc_driver_impl[6e789f234d303bfb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[2185e438fa60127]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f2afda6786c - <std[1ac9ec7f151dc343]::sys::thread::unix::Thread>::new::thread_start
  30:     0x7f2af74a598b - <unknown>
  31:     0x7f2af7529a0c - <unknown>
  32:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

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.96.0-nightly (f82485388 2026-03-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `_::Foo` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-extern_item_impls`#![feature(extern_item_impls)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

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