Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
{
return interp_ok(());
}

if tcx.generics_of(def_id).requires_monomorphization(tcx) {
// Skip generic functions: while they can have #[no_mangle] (resulting in a compiler warning),
// foreign items cannot be generic, so this definition cannot match the foreign item we're looking for.
return interp_ok(());
}
let instance = Instance::mono(tcx, def_id);
let symbol_name = tcx.symbol_name(instance).name;
let is_weak = attrs.linkage == Some(Linkage::WeakAny);
Expand Down
9 changes: 9 additions & 0 deletions tests/pass/issues/issue-154385-no-mangle-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
foo(1234);
}

#[allow(no_mangle_generic_items)]
#[unsafe(no_mangle)]
fn foo<T: std::fmt::Debug>(value: T) {
println!("{value:?}");
}
1 change: 1 addition & 0 deletions tests/pass/issues/issue-154385-no-mangle-generic.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234
Loading