diff options
| author | jumbatm <30644300+jumbatm@users.noreply.github.com> | 2020-12-13 23:02:32 +1000 |
|---|---|---|
| committer | jumbatm <30644300+jumbatm@users.noreply.github.com> | 2021-01-12 03:31:00 +1000 |
| commit | 15c64a181b93584572f568a4c135a0fdb2870eb6 (patch) | |
| tree | 6030e95411750073379dc0189c60d2c3d3261324 | |
| parent | 6318db1c5a06a08a6b4063b25a63df3c328a5bd7 (diff) | |
| download | rust-15c64a181b93584572f568a4c135a0fdb2870eb6.tar.gz rust-15c64a181b93584572f568a4c135a0fdb2870eb6.zip | |
Use tcx.symbol_name to check for clashes.
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 374bd6d0d79..0ef67a13556 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -43,6 +43,7 @@ use rustc_index::vec::Idx; use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, Subst}; +use rustc_middle::ty::Instance; use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt}; use rustc_session::Session; use rustc_span::edition::Edition; @@ -2595,7 +2596,7 @@ declare_lint! { } pub struct ClashingExternDeclarations { - seen_decls: FxHashMap<Symbol, HirId>, + seen_decls: FxHashMap<String, HirId>, } /// Differentiate between whether the name for an extern decl came from the link_name attribute or @@ -2626,16 +2627,17 @@ impl ClashingExternDeclarations { fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> { let hid = fi.hir_id; - 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) { + 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.to_string(); + if self.seen_decls.contains_key(&name) { // 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. - Some(*self.seen_decls.get(name).unwrap()) + Some(*self.seen_decls.get(&name).unwrap()) } else { - self.seen_decls.insert(*name, hid) + self.seen_decls.insert(name, hid) } } |
