From 1b9d0584a044cf63259601498cfd2a70ab213284 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Mon, 4 Dec 2017 21:17:42 -0800 Subject: [PATCH] Add field `is_import` to `def::Export`. --- src/librustc/hir/def.rs | 2 ++ src/librustc/ich/impls_hir.rs | 3 ++- src/librustc_metadata/decoder.rs | 14 ++++++++++---- src/librustc_resolve/build_reduced_graph.rs | 4 ++-- src/librustc_resolve/macros.rs | 1 + src/librustc_resolve/resolve_imports.rs | 1 + src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/visit_lib.rs | 4 +++- 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index a82c2f08463a6..3ef0633e7f400 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -130,6 +130,8 @@ pub struct Export { /// The visibility of the export. /// We include non-`pub` exports for hygienic macros that get used from extern crates. pub vis: ty::Visibility, + /// True if from a `use` or and `extern crate`. + pub is_import: bool, } impl CtorKind { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index a02efe7bd862d..f553e2afc4b48 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -1163,7 +1163,8 @@ impl_stable_hash_for!(struct hir::def::Export { ident, def, vis, - span + span, + is_import }); impl<'gcx> HashStable> diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index e2ad5fbf22b39..948bbe7edc5ba 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -636,6 +636,7 @@ impl<'a, 'tcx> CrateMetadata { def: def, vis: ty::Visibility::Public, span: DUMMY_SP, + is_import: false, }); } } @@ -675,6 +676,7 @@ impl<'a, 'tcx> CrateMetadata { ident: Ident::from_str(&self.item_name(child_index)), vis: self.get_visibility(child_index), span: self.entry(child_index).span.decode((self, sess)), + is_import: false, }); } } @@ -692,7 +694,8 @@ impl<'a, 'tcx> CrateMetadata { (self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) { let ident = Ident::from_str(&name); let vis = self.get_visibility(child_index); - callback(def::Export { def, ident, vis, span }); + let is_import = false; + callback(def::Export { def, ident, vis, span, is_import }); // For non-reexport structs and variants add their constructors to children. // Reexport lists automatically contain constructors when necessary. match def { @@ -700,8 +703,11 @@ impl<'a, 'tcx> CrateMetadata { if let Some(ctor_def_id) = self.get_struct_ctor_def_id(child_index) { let ctor_kind = self.get_ctor_kind(child_index); let ctor_def = Def::StructCtor(ctor_def_id, ctor_kind); - let vis = self.get_visibility(ctor_def_id.index); - callback(def::Export { def: ctor_def, ident, vis, span }); + callback(def::Export { + def: ctor_def, + vis: self.get_visibility(ctor_def_id.index), + ident, span, is_import, + }); } } Def::Variant(def_id) => { @@ -710,7 +716,7 @@ impl<'a, 'tcx> CrateMetadata { let ctor_kind = self.get_ctor_kind(child_index); let ctor_def = Def::VariantCtor(def_id, ctor_kind); let vis = self.get_visibility(child_index); - callback(def::Export { def: ctor_def, ident, vis, span }); + callback(def::Export { def: ctor_def, ident, vis, span, is_import }); } _ => {} } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index f19c1998d10d2..33fe432f0670a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -466,7 +466,7 @@ impl<'a> Resolver<'a> { /// Builds the reduced graph for a single item in an external crate. fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'a>, child: Export) { - let Export { ident, def, vis, span } = child; + let Export { ident, def, vis, span, .. } = child; let def_id = def.def_id(); let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene match def { @@ -672,7 +672,7 @@ impl<'a> Resolver<'a> { let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span); if let Ok(binding) = result { let (def, vis) = (binding.def(), binding.vis); - self.macro_exports.push(Export { ident, def, vis, span }); + self.macro_exports.push(Export { ident, def, vis, span, is_import: true }); } else { span_err!(self.session, span, E0470, "reexported macro not found"); } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index ad1e70a5c6ec7..f2162f2321f61 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -751,6 +751,7 @@ impl<'a> Resolver<'a> { def: def, vis: ty::Visibility::Public, span: item.span, + is_import: false, }); } else { self.unused_macros.insert(def_id); diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index e885ec53631bd..ed66a1c2d79b8 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -866,6 +866,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { def: def, span: binding.span, vis: binding.vis, + is_import: true, }); } } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 85c1796ecef39..79e3d48843c03 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -391,7 +391,7 @@ fn build_module(cx: &DocContext, did: DefId) -> clean::Module { let mut visited = FxHashSet(); for &item in cx.tcx.item_children(did).iter() { let def_id = item.def.def_id(); - if cx.tcx.visibility(def_id) == ty::Visibility::Public { + if item.vis == ty::Visibility::Public { if !visited.insert(def_id) { continue } if let Some(i) = try_inline(cx, item.def, item.ident.name) { items.extend(i) diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 9f75388238f0c..2fd47fa0a6d0a 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -68,7 +68,9 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> { } for item in self.cx.tcx.item_children(def_id).iter() { - self.visit_item(item.def); + if !item.is_import || item.vis == Visibility::Public { + self.visit_item(item.def); + } } }