extract Export, ExportMap from hir::def
This commit is contained in:
parent
702b2d736a
commit
1f7b4e9a59
12 changed files with 75 additions and 65 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
pub mod check_attr;
|
||||
pub mod def;
|
||||
pub mod exports;
|
||||
pub use rustc_hir::def_id;
|
||||
pub use rustc_hir::hir_id::*;
|
||||
pub mod intravisit;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
use crate::hir;
|
||||
use crate::hir::def_id::{DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use crate::ty;
|
||||
use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::Span;
|
||||
use syntax::ast;
|
||||
use syntax::ast::NodeId;
|
||||
|
||||
|
|
@ -293,29 +291,6 @@ impl<T> PerNS<Option<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// This is the replacement export map. It maps a module to all of the exports
|
||||
/// within.
|
||||
pub type ExportMap<Id> = DefIdMap<Vec<Export<Id>>>;
|
||||
|
||||
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub struct Export<Id> {
|
||||
/// The name of the target.
|
||||
pub ident: ast::Ident,
|
||||
/// The resolution of the target.
|
||||
pub res: Res<Id>,
|
||||
/// The span of the target.
|
||||
pub span: Span,
|
||||
/// The visibility of the export.
|
||||
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
|
||||
pub vis: ty::Visibility,
|
||||
}
|
||||
|
||||
impl<Id> Export<Id> {
|
||||
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
|
||||
Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis }
|
||||
}
|
||||
}
|
||||
|
||||
impl CtorKind {
|
||||
pub fn from_ast(vdata: &ast::VariantData) -> CtorKind {
|
||||
match *vdata {
|
||||
|
|
|
|||
32
src/librustc/hir/exports.rs
Normal file
32
src/librustc/hir/exports.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use crate::hir::def::Res;
|
||||
use crate::hir::def_id::DefIdMap;
|
||||
use crate::ty;
|
||||
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_span::Span;
|
||||
use syntax::ast;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// This is the replacement export map. It maps a module to all of the exports
|
||||
/// within.
|
||||
pub type ExportMap<Id> = DefIdMap<Vec<Export<Id>>>;
|
||||
|
||||
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub struct Export<Id> {
|
||||
/// The name of the target.
|
||||
pub ident: ast::Ident,
|
||||
/// The resolution of the target.
|
||||
pub res: Res<Id>,
|
||||
/// The span of the target.
|
||||
pub span: Span,
|
||||
/// The visibility of the export.
|
||||
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
|
||||
pub vis: ty::Visibility,
|
||||
}
|
||||
|
||||
impl<Id> Export<Id> {
|
||||
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
|
||||
Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis }
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,9 @@
|
|||
use crate::arena::Arena;
|
||||
use crate::dep_graph::DepGraph;
|
||||
use crate::dep_graph::{self, DepConstructor, DepNode};
|
||||
use crate::hir::def::{DefKind, Export, Res};
|
||||
use crate::hir::def::{DefKind, Res};
|
||||
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
|
||||
use crate::hir::exports::Export;
|
||||
use crate::hir::map as hir_map;
|
||||
use crate::hir::map::DefPathHash;
|
||||
use crate::hir::{self, HirId, Node, TraitCandidate};
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ pub use self::BorrowKind::*;
|
|||
pub use self::IntVarValue::*;
|
||||
pub use self::Variance::*;
|
||||
|
||||
use crate::hir::def::{CtorKind, CtorOf, DefKind, ExportMap, Res};
|
||||
use crate::hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use crate::hir::exports::ExportMap;
|
||||
use crate::hir::Node;
|
||||
use crate::hir::{map as hir_map, GlobMap, TraitMap};
|
||||
use crate::ich::Fingerprint;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::dep_graph::{self, DepNode};
|
||||
use crate::hir::def::{DefKind, Export};
|
||||
use crate::hir::def::DefKind;
|
||||
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex};
|
||||
use crate::hir::exports::Export;
|
||||
use crate::hir::{self, HirIdSet, ItemLocalId, TraitCandidate};
|
||||
use crate::infer::canonical::{self, Canonical};
|
||||
use crate::lint;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ use crate::rmeta::*;
|
|||
|
||||
use rustc::dep_graph::{self, DepNodeIndex};
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, Res};
|
||||
use rustc::hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc::hir::exports::Export;
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
|
||||
use rustc::middle::cstore::{CrateSource, ExternCrate};
|
||||
|
|
@ -930,7 +931,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
/// Iterates over each child of the given item.
|
||||
fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
|
||||
where
|
||||
F: FnMut(def::Export<hir::HirId>),
|
||||
F: FnMut(Export<hir::HirId>),
|
||||
{
|
||||
if let Some(proc_macros_ids) = self.root.proc_macro_data.map(|d| d.decode(self)) {
|
||||
/* If we are loading as a proc macro, we want to return the view of this crate
|
||||
|
|
@ -944,12 +945,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
self.local_def_id(def_index),
|
||||
);
|
||||
let ident = Ident::from_str(raw_macro.name());
|
||||
callback(def::Export {
|
||||
ident: ident,
|
||||
res: res,
|
||||
vis: ty::Visibility::Public,
|
||||
span: DUMMY_SP,
|
||||
});
|
||||
callback(Export { ident, res, vis: ty::Visibility::Public, span: DUMMY_SP });
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
@ -989,7 +985,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
.unwrap_or(Lazy::empty());
|
||||
for child_index in child_children.decode((self, sess)) {
|
||||
if let Some(kind) = self.def_kind(child_index) {
|
||||
callback(def::Export {
|
||||
callback(Export {
|
||||
res: Res::Def(kind, self.local_def_id(child_index)),
|
||||
ident: Ident::with_dummy_span(self.item_name(child_index)),
|
||||
vis: self.get_visibility(child_index),
|
||||
|
|
@ -1019,7 +1015,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
let vis = self.get_visibility(child_index);
|
||||
let def_id = self.local_def_id(child_index);
|
||||
let res = Res::Def(kind, def_id);
|
||||
callback(def::Export { res, ident, vis, span });
|
||||
callback(Export { res, ident, vis, span });
|
||||
// For non-re-export structs and variants add their constructors to children.
|
||||
// Re-export lists automatically contain constructors when necessary.
|
||||
match kind {
|
||||
|
|
@ -1029,7 +1025,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
let ctor_res =
|
||||
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
|
||||
let vis = self.get_visibility(ctor_def_id.index);
|
||||
callback(def::Export { res: ctor_res, vis, ident, span });
|
||||
callback(Export { res: ctor_res, vis, ident, span });
|
||||
}
|
||||
}
|
||||
DefKind::Variant => {
|
||||
|
|
@ -1053,7 +1049,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
vis = ty::Visibility::Restricted(crate_def_id);
|
||||
}
|
||||
}
|
||||
callback(def::Export { res: ctor_res, ident, vis, span });
|
||||
callback(Export { res: ctor_res, ident, vis, span });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use crate::native_libs;
|
|||
use crate::rmeta::{self, encoder};
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::def;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc::hir::exports::Export;
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
|
||||
use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind};
|
||||
|
|
@ -342,29 +342,28 @@ pub fn provide(providers: &mut Providers<'_>) {
|
|||
// (restrict scope of mutable-borrow of `visible_parent_map`)
|
||||
{
|
||||
let visible_parent_map = &mut visible_parent_map;
|
||||
let mut add_child = |bfs_queue: &mut VecDeque<_>,
|
||||
child: &def::Export<hir::HirId>,
|
||||
parent: DefId| {
|
||||
if child.vis != ty::Visibility::Public {
|
||||
return;
|
||||
}
|
||||
let mut add_child =
|
||||
|bfs_queue: &mut VecDeque<_>, child: &Export<hir::HirId>, parent: DefId| {
|
||||
if child.vis != ty::Visibility::Public {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(child) = child.res.opt_def_id() {
|
||||
match visible_parent_map.entry(child) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
// If `child` is defined in crate `cnum`, ensure
|
||||
// that it is mapped to a parent in `cnum`.
|
||||
if child.krate == cnum && entry.get().krate != cnum {
|
||||
if let Some(child) = child.res.opt_def_id() {
|
||||
match visible_parent_map.entry(child) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
// If `child` is defined in crate `cnum`, ensure
|
||||
// that it is mapped to a parent in `cnum`.
|
||||
if child.krate == cnum && entry.get().krate != cnum {
|
||||
entry.insert(parent);
|
||||
}
|
||||
}
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(parent);
|
||||
bfs_queue.push_back(child);
|
||||
}
|
||||
}
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(parent);
|
||||
bfs_queue.push_back(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
while let Some(def) = bfs_queue.pop_front() {
|
||||
for child in tcx.item_children(def).iter() {
|
||||
|
|
@ -410,7 +409,7 @@ impl CStore {
|
|||
&self,
|
||||
def_id: DefId,
|
||||
sess: &Session,
|
||||
) -> Vec<def::Export<hir::HirId>> {
|
||||
) -> Vec<Export<hir::HirId>> {
|
||||
let mut result = vec![];
|
||||
self.get_crate_data(def_id.krate).each_child_of_item(
|
||||
def_id.index,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ use decoder::Metadata;
|
|||
use table::{Table, TableBuilder};
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::{self, CtorKind};
|
||||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{DefId, DefIndex};
|
||||
use rustc::hir::exports::Export;
|
||||
use rustc::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLibrary};
|
||||
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc::middle::lang_items;
|
||||
|
|
@ -317,7 +318,7 @@ struct RenderedConst(String);
|
|||
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
struct ModData {
|
||||
reexports: Lazy<[def::Export<hir::HirId>]>,
|
||||
reexports: Lazy<[Export<hir::HirId>]>,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segmen
|
|||
use rustc::bug;
|
||||
use rustc::hir::def::{self, *};
|
||||
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc::hir::exports::Export;
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc::ty;
|
||||
use rustc_metadata::creader::LoadedMacro;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBindin
|
|||
|
||||
use errors::{pluralize, Applicability};
|
||||
|
||||
use rustc::hir::def::{self, Export, PartialRes};
|
||||
use rustc::hir::def::{self, PartialRes};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::exports::Export;
|
||||
use rustc::lint::builtin::BuiltinLintDiagnostics;
|
||||
use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS};
|
||||
use rustc::session::DiagnosticMessageId;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ use Determinacy::*;
|
|||
|
||||
use errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc::hir::def::Namespace::*;
|
||||
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, ExportMap, NonMacroAttrKind, PartialRes};
|
||||
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc::hir::exports::ExportMap;
|
||||
use rustc::hir::map::Definitions;
|
||||
use rustc::hir::{Bool, Char, Float, Int, PrimTy, Str, Uint};
|
||||
use rustc::hir::{GlobMap, TraitMap};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue