@@ -43,6 +43,7 @@ use rustc_index::vec::Idx;
4343use rustc_middle:: lint:: LintDiagnosticBuilder ;
4444use rustc_middle:: ty:: print:: with_no_trimmed_paths;
4545use rustc_middle:: ty:: subst:: { GenericArgKind , Subst } ;
46+ use rustc_middle:: ty:: Instance ;
4647use rustc_middle:: ty:: { self , layout:: LayoutError , Ty , TyCtxt } ;
4748use rustc_session:: Session ;
4849use rustc_span:: edition:: Edition ;
@@ -2595,7 +2596,7 @@ declare_lint! {
25952596}
25962597
25972598pub struct ClashingExternDeclarations {
2598- seen_decls : FxHashMap < Symbol , HirId > ,
2599+ seen_decls : FxHashMap < String , HirId > ,
25992600}
26002601
26012602/// Differentiate between whether the name for an extern decl came from the link_name attribute or
@@ -2626,16 +2627,17 @@ impl ClashingExternDeclarations {
26262627 fn insert ( & mut self , tcx : TyCtxt < ' _ > , fi : & hir:: ForeignItem < ' _ > ) -> Option < HirId > {
26272628 let hid = fi. hir_id ;
26282629
2629- let name =
2630- & tcx. codegen_fn_attrs ( tcx. hir ( ) . local_def_id ( hid) ) . link_name . unwrap_or ( fi. ident . name ) ;
2631-
2632- if self . seen_decls . contains_key ( name) {
2630+ let local_did = tcx. hir ( ) . local_def_id ( fi. hir_id ) ;
2631+ let did = local_did. to_def_id ( ) ;
2632+ let instance = Instance :: new ( did, ty:: List :: identity_for_item ( tcx, did) ) ;
2633+ let name = tcx. symbol_name ( instance) . name . to_string ( ) ;
2634+ if self . seen_decls . contains_key ( & name) {
26332635 // Avoid updating the map with the new entry when we do find a collision. We want to
26342636 // make sure we're always pointing to the first definition as the previous declaration.
26352637 // This lets us avoid emitting "knock-on" diagnostics.
2636- Some ( * self . seen_decls . get ( name) . unwrap ( ) )
2638+ Some ( * self . seen_decls . get ( & name) . unwrap ( ) )
26372639 } else {
2638- self . seen_decls . insert ( * name, hid)
2640+ self . seen_decls . insert ( name, hid)
26392641 }
26402642 }
26412643
0 commit comments