Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. --Rustc 1.48.0 gives an incorrect warning about an external symbol being redeclared with a different signature, when the external symbols are in different namespaces. I tried this code: I expected to see this happen: Compile without warnings Instead, this happened: <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: The same behavior exists on nightly as well: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summaryBacktrace</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
cc
cc would you be willing to help take a look at this? (it looks like you this way-back-when in ) On wasm targets there's which is why this should work but not actually generate a warning. Do you know if it's possible to call that logic perhaps? (would be able to consolidate "what's the name of this symbol" logic too!)
Sure thing! I'm currently in the process of moving, but will be able to get onto this on the weekend :) claim
No worries, and thanks! If you run out of time/steam I'm happy to look into this as well

Discussion:
use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, Subst}; <ins> use rustc_middle::ty::Instance; </ins> use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt}; use rustc_session::Session; use rustc_span::edition::Edition;

} pub struct ClashingExternDeclarations { <del> seen_decls: FxHashMap<Symbol, HirId>, </del> <ins> /// Map of function symbol name to the first-seen hir id for that symbol name.. If seen_decls /// contains an entry for key K, it means a symbol with name K has been seen by this lint and /// the symbol should be reported as a clashing declaration. // FIXME: Technically, we could just store a &'tcx str here without issue; however, the // `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime. seen_decls: FxHashMap<String, HirId>, </ins> } /// Differentiate between whether the name for an extern decl came from the link_name attribute or

fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> { let hid = fi.hir_id; <del> let name = &tcx.codegen_fn_attrs(tcx.hir().local_def_id(hid)).link_name.unwrap_or(fi.ident.name); if self.seen_decls.contains_key(name) { </del> <ins> let local_did = tcx.hir().local_def_id(fi.hir_id); let did = local_did.to_def_id(); let instance = Instance::new(did, ty::List::identity_for_item(tcx, did)); let name = tcx.symbol_name(instance).name; if let Some(&hir_id) = self.seen_decls.get(name) { </ins> // Avoid updating the map with the new entry when we do find a collision. We want to // make sure we're always pointing to the first definition as the previous declaration. // This lets us avoid emitting "knock-on" diagnostics. <del> Some(*self.seen_decls.get(name).unwrap()) </del> <ins> Some(hir_id) </ins> } else { <del> self.seen_decls.insert(*name, hid) </del> <ins> self.seen_decls.insert(name.to_owned(), hid) </ins> } }

<ins> // check-pass #![crate_type = "lib"] #[cfg(target_arch = "wasm32")] mod wasm_non_clash { mod a { #[link(wasm_import_module = "a")] extern "C" { pub fn foo(); } } mod b { #[link(wasm_import_module = "b")] extern "C" { pub fn foo() -> usize; // #79581: These declarations shouldn't clash because foreign fn names are mangled // on wasm32. } } } </ins>