]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/hir/map/collector.rs
Do not visit ForeignItemRef for HIR indexing and validation.
[rust.git] / compiler / rustc_middle / src / hir / map / collector.rs
index 516c9b6752b97afa46636b3fffe66a6896880c56..82cfca4f17101630d58eb62ecd73f633ad503681 100644 (file)
@@ -112,6 +112,7 @@ pub(super) fn root(
                 items: _,
                 trait_items: _,
                 impl_items: _,
+                foreign_items: _,
                 bodies: _,
                 trait_impls: _,
                 body_ids: _,
@@ -319,6 +320,10 @@ fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
         self.visit_impl_item(self.krate.impl_item(item_id));
     }
 
+    fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
+        self.visit_foreign_item(self.krate.foreign_item(foreign_id));
+    }
+
     fn visit_nested_body(&mut self, id: BodyId) {
         self.visit_body(self.krate.body(id));
     }
@@ -351,11 +356,17 @@ fn visit_item(&mut self, i: &'hir Item<'hir>) {
         });
     }
 
-    fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem<'hir>) {
-        self.insert(foreign_item.span, foreign_item.hir_id, Node::ForeignItem(foreign_item));
+    fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
+        debug_assert_eq!(
+            fi.hir_id.owner,
+            self.definitions.opt_hir_id_to_local_def_id(fi.hir_id).unwrap()
+        );
+        self.with_dep_node_owner(fi.hir_id.owner, fi, |this, hash| {
+            this.insert_with_hash(fi.span, fi.hir_id, Node::ForeignItem(fi), hash);
 
-        self.with_parent(foreign_item.hir_id, |this| {
-            intravisit::walk_foreign_item(this, foreign_item);
+            this.with_parent(fi.hir_id, |this| {
+                intravisit::walk_foreign_item(this, fi);
+            });
         });
     }
 
@@ -561,6 +572,14 @@ fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef<'hir>) {
 
         self.visit_nested_impl_item(id);
     }
+
+    fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef<'hir>) {
+        // Do not visit the duplicate information in ForeignItemRef. We want to
+        // map the actual nodes, not the duplicate ones in the *Ref.
+        let ForeignItemRef { id, ident: _, span: _, vis: _ } = *fi;
+
+        self.visit_nested_foreign_item(id);
+    }
 }
 
 struct HirItemLike<T> {