Skip to content

[ICE]: Unexpected type for raw-dylib: foreign type #154111

@matthiaskrgr

Description

@matthiaskrgr

snippet:

#![feature(extern_types)]
#![feature(raw_dylib_elf)]
#![crate_type = "lib"]
#[link(name = "foo", kind = "raw-dylib")]
unsafe extern "C" {
    type X;
}

Version information

rustc 1.96.0-nightly (1f7f8ea07 2026-03-19)
binary: rustc
commit-hash: 1f7f8ea0721a3b1eb73e6c6d25cccb371434b320
commit-date: 2026-03-19
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
DllImportSymbolType::ThreadLocal
} else {
DllImportSymbolType::Static
}
} else {
bug!("Unexpected type for raw-dylib: {}", def_kind.descr(item));
};
let size = match symbol_type {
// We cannot determine the size of a function at compile time, but it shouldn't matter anyway.
DllImportSymbolType::Function => rustc_abi::Size::ZERO,
DllImportSymbolType::Static | DllImportSymbolType::ThreadLocal => {

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

Program output

warning: the feature `raw_dylib_elf` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.SrpraHE9Vwgd/rustc_testrunner_tmpdir_reporting.qFASUYLXg62j/mvce.rs:2:12
  |
2 | #![feature(raw_dylib_elf)]
  |            ^^^^^^^^^^^^^
  |
  = note: see issue #135694 <https://github.com/rust-lang/rust/issues/135694> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: foreign type `X` is never used
 --> /tmp/icemaker_global_tempdir.SrpraHE9Vwgd/rustc_testrunner_tmpdir_reporting.qFASUYLXg62j/mvce.rs:6:10
  |
6 |     type X;
  |          ^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: internal compiler error: /rustc-dev/1f7f8ea0721a3b1eb73e6c6d25cccb371434b320/compiler/rustc_metadata/src/native_libs.rs:469:13: Unexpected type for raw-dylib: foreign type


thread 'rustc' (1256827) panicked at /rustc-dev/1f7f8ea0721a3b1eb73e6c6d25cccb371434b320/compiler/rustc_metadata/src/native_libs.rs:469:13:
Box<dyn Any>
stack backtrace:
   0:     0x7f1daed26dcb - <<std[f92b4c606f291077]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[786f478f706679df]::fmt::Display>::fmt
   1:     0x7f1daf42f1c8 - core[786f478f706679df]::fmt::write
   2:     0x7f1daed3ddd6 - <std[f92b4c606f291077]::sys::stdio::unix::Stderr as std[f92b4c606f291077]::io::Write>::write_fmt
   3:     0x7f1daecfce08 - std[f92b4c606f291077]::panicking::default_hook::{closure#0}
   4:     0x7f1daed1a1d3 - std[f92b4c606f291077]::panicking::default_hook
   5:     0x7f1dadd1e0bc - std[f92b4c606f291077]::panicking::update_hook::<alloc[64763625b5a07cdb]::boxed::Box<rustc_driver_impl[dd146e1c86fe9c2a]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f1daed1a4b2 - std[f92b4c606f291077]::panicking::panic_with_hook
   7:     0x7f1dadd4d741 - std[f92b4c606f291077]::panicking::begin_panic::<rustc_errors[5aeff7798fb65382]::ExplicitBug>::{closure#0}
   8:     0x7f1dadd46426 - std[f92b4c606f291077]::sys::backtrace::__rust_end_short_backtrace::<std[f92b4c606f291077]::panicking::begin_panic<rustc_errors[5aeff7798fb65382]::ExplicitBug>::{closure#0}, !>
   9:     0x7f1dadd4618b - std[f92b4c606f291077]::panicking::begin_panic::<rustc_errors[5aeff7798fb65382]::ExplicitBug>
  10:     0x7f1dadd58db1 - <rustc_errors[5aeff7798fb65382]::diagnostic::BugAbort as rustc_errors[5aeff7798fb65382]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f1dae336cc9 - rustc_middle[9da1fcba01c2e50a]::util::bug::opt_span_bug_fmt::<rustc_span[6852aeac55da1279]::span_encoding::Span>::{closure#0}
  12:     0x7f1dae336e52 - rustc_middle[9da1fcba01c2e50a]::ty::context::tls::with_opt::<rustc_middle[9da1fcba01c2e50a]::util::bug::opt_span_bug_fmt<rustc_span[6852aeac55da1279]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f1dae32792b - rustc_middle[9da1fcba01c2e50a]::ty::context::tls::with_context_opt::<rustc_middle[9da1fcba01c2e50a]::ty::context::tls::with_opt<rustc_middle[9da1fcba01c2e50a]::util::bug::opt_span_bug_fmt<rustc_span[6852aeac55da1279]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f1dabb7ce44 - rustc_middle[9da1fcba01c2e50a]::util::bug::bug_fmt
  15:     0x7f1dafddfb75 - rustc_metadata[ca98268c3045dc4]::native_libs::collect
  16:     0x7f1db033894e - rustc_query_impl[c721b7e622170968]::query_impl::native_libraries::invoke_provider_fn::__rust_begin_short_backtrace
  17:     0x7f1db033665a - rustc_query_impl[c721b7e622170968]::execution::try_execute_query::<rustc_data_structures[943c71a52384e02b]::vec_cache::VecCache<rustc_span[6852aeac55da1279]::def_id::CrateNum, rustc_middle[9da1fcba01c2e50a]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[9da1fcba01c2e50a]::dep_graph::graph::DepNodeIndex>, false>
  18:     0x7f1db0336303 - rustc_query_impl[c721b7e622170968]::query_impl::native_libraries::execute_query_non_incr::__rust_end_short_backtrace
  19:     0x7f1dafe3b08a - <rustc_metadata[ca98268c3045dc4]::rmeta::encoder::EncodeContext>::encode_crate_root
  20:     0x7f1db07ec83a - <rustc_metadata[ca98268c3045dc4]::rmeta::encoder::encode_metadata::{closure#3} as core[786f478f706679df]::ops::function::FnOnce<(rustc_middle[9da1fcba01c2e50a]::ty::context::TyCtxt, &std[f92b4c606f291077]::path::Path)>>::call_once
  21:     0x7f1db07e9f94 - rustc_metadata[ca98268c3045dc4]::rmeta::encoder::encode_metadata
  22:     0x7f1db0147049 - rustc_metadata[ca98268c3045dc4]::fs::encode_and_write_metadata
  23:     0x7f1db062a6d0 - <rustc_interface[13b2c4b636310a2c]::queries::Linker>::codegen_and_build_linker
  24:     0x7f1db06253cd - rustc_interface[13b2c4b636310a2c]::interface::run_compiler::<(), rustc_driver_impl[dd146e1c86fe9c2a]::run_compiler::{closure#0}>::{closure#1}
  25:     0x7f1db060943e - std[f92b4c606f291077]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[13b2c4b636310a2c]::util::run_in_thread_with_globals<rustc_interface[13b2c4b636310a2c]::util::run_in_thread_pool_with_globals<rustc_interface[13b2c4b636310a2c]::interface::run_compiler<(), rustc_driver_impl[dd146e1c86fe9c2a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x7f1db0609ce0 - <std[f92b4c606f291077]::thread::lifecycle::spawn_unchecked<rustc_interface[13b2c4b636310a2c]::util::run_in_thread_with_globals<rustc_interface[13b2c4b636310a2c]::util::run_in_thread_pool_with_globals<rustc_interface[13b2c4b636310a2c]::interface::run_compiler<(), rustc_driver_impl[dd146e1c86fe9c2a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[786f478f706679df]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7f1db060ab6c - <std[f92b4c606f291077]::sys::thread::unix::Thread>::new::thread_start
  28:     0x7f1daa0a597a - <unknown>
  29:     0x7f1daa1292bc - <unknown>
  30:                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.96.0-nightly (1f7f8ea07 2026-03-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [native_libraries] looking up the native libraries of a linked crate
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@rustbot label +F-extern_types +F-raw_dylib_elf

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-extern_types`#![feature(extern_types)]`F-raw_dylib`#![feature(raw_dylib)]`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