]> git.lizzy.rs Git - rust.git/commitdiff
Do not visit ForeignItemRef for HIR indexing and validation.
authorCamille GILLOT <gillot.camille@gmail.com>
Sat, 28 Nov 2020 17:08:11 +0000 (18:08 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Sat, 28 Nov 2020 17:08:17 +0000 (18:08 +0100)
Similarly to what is done for ImplItemRef and TraitItemRef.

Fixes #79487

compiler/rustc_middle/src/hir/map/collector.rs
compiler/rustc_passes/src/hir_id_validator.rs
src/test/ui/foreign/foreign-pub-super.rs [new file with mode: 0644]

index 912e9672c94183918644410e2aa94cb352b94ec0..82cfca4f17101630d58eb62ecd73f633ad503681 100644 (file)
@@ -572,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> {
index c7e057927ab42065d330075261710d03d4e9526c..fdd6c2380556473da5fdb0e00c2b42de067c0c4c 100644 (file)
@@ -169,6 +169,13 @@ fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef<'hir>) {
         // different owner.
     }
 
+    fn visit_foreign_item_ref(&mut self, _: &'hir hir::ForeignItemRef<'hir>) {
+        // Explicitly do nothing here. ForeignItemRefs contain hir::Visibility
+        // values that actually belong to an ForeignItem instead of the ItemKind::ForeignMod
+        // we are currently in. So for those it's correct that they have a
+        // different owner.
+    }
+
     fn visit_generic_param(&mut self, param: &'hir hir::GenericParam<'hir>) {
         if let hir::GenericParamKind::Type {
             synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
diff --git a/src/test/ui/foreign/foreign-pub-super.rs b/src/test/ui/foreign/foreign-pub-super.rs
new file mode 100644 (file)
index 0000000..19f9e4e
--- /dev/null
@@ -0,0 +1,12 @@
+// Test for #79487
+// check-pass
+
+#![allow(dead_code)]
+
+mod sha2 {
+    extern "C" {
+        pub(super) fn GFp_sha512_block_data_order();
+    }
+}
+
+fn main() {}