From 7a46a4f2197c6ff1026d2bd81480165ad0b43bbc Mon Sep 17 00:00:00 2001 From: jumbatm <30644300+jumbatm@users.noreply.github.com> Date: Wed, 23 Dec 2020 00:26:04 +1000 Subject: [PATCH] Remove unnecessary allocation. --- compiler/rustc_lint/src/builtin.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 0ef67a135560..131d783ce4e2 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2630,14 +2630,14 @@ impl ClashingExternDeclarations { 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) { + let name = tcx.symbol_name(instance).name; + if let Some(&hir_id) = self.seen_decls.get(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(hir_id) } else { - self.seen_decls.insert(name, hid) + self.seen_decls.insert(name.to_owned(), hid) } }