]> git.lizzy.rs Git - rust.git/commitdiff
Don't call `local_def_id` twice on the same node id
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Mon, 16 Jul 2018 09:19:36 +0000 (11:19 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Wed, 18 Jul 2018 08:53:08 +0000 (10:53 +0200)
src/librustc_typeck/collect.rs

index ab81cb8788f9c4172cbcd7a40255b39eb82f5c77..e9510d118f7d4d48d2905f806cfd3ef0d6880268 100644 (file)
@@ -1185,8 +1185,7 @@ struct ConstraintLocator<'a, 'tcx: 'a> {
         found: Option<(Span, ty::Ty<'tcx>)>,
     }
     impl<'a, 'tcx> ConstraintLocator<'a, 'tcx> {
-        fn check(&mut self, node_id: ast::NodeId) {
-            let def_id = self.tcx.hir.local_def_id(node_id);
+        fn check(&mut self, def_id: DefId) {
             // don't try to check items that cannot possibly constrain the type
             if !self.tcx.has_typeck_tables(def_id) {
                 return;
@@ -1221,21 +1220,24 @@ fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'thi
             intravisit::NestedVisitorMap::All(&self.tcx.hir)
         }
         fn visit_item(&mut self, it: &'tcx Item) {
+            let def_id = self.tcx.hir.local_def_id(it.id);
             // the existential type itself or its children are not within its reveal scope
-            if self.tcx.hir.local_def_id(it.id) != self.def_id {
-                self.check(it.id);
+            if def_id != self.def_id {
+                self.check(def_id);
                 intravisit::walk_item(self, it);
             }
         }
         fn visit_impl_item(&mut self, it: &'tcx ImplItem) {
+            let def_id = self.tcx.hir.local_def_id(it.id);
             // the existential type itself or its children are not within its reveal scope
-            if self.tcx.hir.local_def_id(it.id) != self.def_id {
-                self.check(it.id);
+            if def_id != self.def_id {
+                self.check(def_id);
                 intravisit::walk_impl_item(self, it);
             }
         }
         fn visit_trait_item(&mut self, it: &'tcx TraitItem) {
-            self.check(it.id);
+            let def_id = self.tcx.hir.local_def_id(it.id);
+            self.check(def_id);
             intravisit::walk_trait_item(self, it);
         }
     }