From 860813dd9d63a2cf160801b59295ebb0d2063385 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 8 May 2026 15:17:44 +0200 Subject: [PATCH] Require EIIs to be defined when we compile a rust dylib The linker will complain about undefined symbols otherwise and on object file formats with two level namespaces (Mach-O and PE/COFF) it is required to know which dylib a symbol will be imported from when linking a dylib or executable. --- compiler/rustc_passes/src/eii.rs | 4 ++-- tests/ui/eii/dylib_needs_impl.rs | 7 +++++++ tests/ui/eii/dylib_needs_impl.stderr | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/ui/eii/dylib_needs_impl.rs create mode 100644 tests/ui/eii/dylib_needs_impl.stderr diff --git a/compiler/rustc_passes/src/eii.rs b/compiler/rustc_passes/src/eii.rs index f3e84665f21d..2916f5355e7b 100644 --- a/compiler/rustc_passes/src/eii.rs +++ b/compiler/rustc_passes/src/eii.rs @@ -18,8 +18,8 @@ enum CheckingMode { } fn get_checking_mode(tcx: TyCtxt<'_>) -> CheckingMode { - // if any of the crate types is not rlib or dylib, we must check for existence. - if tcx.crate_types().iter().any(|i| !matches!(i, CrateType::Rlib | CrateType::Dylib)) { + // if any of the crate types is not rlib, we must check for existence. + if tcx.crate_types().iter().any(|i| !matches!(i, CrateType::Rlib)) { CheckingMode::CheckExistence } else { CheckingMode::CheckDuplicates diff --git a/tests/ui/eii/dylib_needs_impl.rs b/tests/ui/eii/dylib_needs_impl.rs new file mode 100644 index 000000000000..bb1ec22b0488 --- /dev/null +++ b/tests/ui/eii/dylib_needs_impl.rs @@ -0,0 +1,7 @@ +//@ no-prefer-dynamic +//@ needs-crate-type: dylib +#![crate_type = "dylib"] +#![feature(extern_item_impls)] + +#[eii(eii1)] //~ ERROR `#[eii1]` required, but not found +fn decl1(x: u64); diff --git a/tests/ui/eii/dylib_needs_impl.stderr b/tests/ui/eii/dylib_needs_impl.stderr new file mode 100644 index 000000000000..60ef656c3017 --- /dev/null +++ b/tests/ui/eii/dylib_needs_impl.stderr @@ -0,0 +1,10 @@ +error: `#[eii1]` required, but not found + --> $DIR/dylib_needs_impl.rs:6:7 + | +LL | #[eii(eii1)] + | ^^^^ expected because `#[eii1]` was declared here in crate `dylib_needs_impl` + | + = help: expected at least one implementation in crate `dylib_needs_impl` or any of its dependencies + +error: aborting due to 1 previous error +