@@ -43,6 +43,7 @@ use rustc_index::vec::Idx;
43
43
use rustc_middle:: lint:: LintDiagnosticBuilder ;
44
44
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
45
45
use rustc_middle:: ty:: subst:: { GenericArgKind , Subst } ;
46
+ use rustc_middle:: ty:: Instance ;
46
47
use rustc_middle:: ty:: { self , layout:: LayoutError , Ty , TyCtxt } ;
47
48
use rustc_session:: Session ;
48
49
use rustc_span:: edition:: Edition ;
@@ -2595,7 +2596,12 @@ declare_lint! {
2595
2596
}
2596
2597
2597
2598
pub struct ClashingExternDeclarations {
2598
- seen_decls : FxHashMap < Symbol , HirId > ,
2599
+ /// Map of function symbol name to the first-seen hir id for that symbol name.. If seen_decls
2600
+ /// contains an entry for key K, it means a symbol with name K has been seen by this lint and
2601
+ /// the symbol should be reported as a clashing declaration.
2602
+ // FIXME: Technically, we could just store a &'tcx str here without issue; however, the
2603
+ // `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
2604
+ seen_decls : FxHashMap < String , HirId > ,
2599
2605
}
2600
2606
2601
2607
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
@@ -2626,16 +2632,17 @@ impl ClashingExternDeclarations {
2626
2632
fn insert ( & mut self , tcx : TyCtxt < ' _ > , fi : & hir:: ForeignItem < ' _ > ) -> Option < HirId > {
2627
2633
let hid = fi. hir_id ;
2628
2634
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) {
2635
+ let local_did = tcx. hir ( ) . local_def_id ( fi. hir_id ) ;
2636
+ let did = local_did. to_def_id ( ) ;
2637
+ let instance = Instance :: new ( did, ty:: List :: identity_for_item ( tcx, did) ) ;
2638
+ let name = tcx. symbol_name ( instance) . name ;
2639
+ if let Some ( & hir_id) = self . seen_decls . get ( name) {
2633
2640
// Avoid updating the map with the new entry when we do find a collision. We want to
2634
2641
// make sure we're always pointing to the first definition as the previous declaration.
2635
2642
// This lets us avoid emitting "knock-on" diagnostics.
2636
- Some ( * self . seen_decls . get ( name ) . unwrap ( ) )
2643
+ Some ( hir_id )
2637
2644
} else {
2638
- self . seen_decls . insert ( * name, hid)
2645
+ self . seen_decls . insert ( name. to_owned ( ) , hid)
2639
2646
}
2640
2647
}
2641
2648
0 commit comments