Skip to content

Commit

Permalink
Add field is_import to def::Export.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Dec 6, 2017
1 parent 58e8040 commit 1b9d058
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/librustc/hir/def.rs
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_hir.rs
Expand Up @@ -1163,7 +1163,8 @@ impl_stable_hash_for!(struct hir::def::Export {
ident,
def,
vis,
span
span,
is_import
});

impl<'gcx> HashStable<StableHashingContext<'gcx>>
Expand Down
14 changes: 10 additions & 4 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -636,6 +636,7 @@ impl<'a, 'tcx> CrateMetadata {
def: def,
vis: ty::Visibility::Public,
span: DUMMY_SP,
is_import: false,
});
}
}
Expand Down Expand Up @@ -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,
});
}
}
Expand All @@ -692,16 +694,20 @@ 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 {
Def::Struct(..) => {
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) => {
Expand All @@ -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 });
}
_ => {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/macros.rs
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -866,6 +866,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
def: def,
span: binding.span,
vis: binding.vis,
is_import: true,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/visit_lib.rs
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 1b9d058

Please sign in to comment.