Skip to content

Commit 1f7b4e9

Browse files
committed
extract Export, ExportMap from hir::def
1 parent 702b2d7 commit 1f7b4e9

File tree

12 files changed

+75
-65
lines changed

12 files changed

+75
-65
lines changed

src/librustc/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
pub mod check_attr;
66
pub mod def;
7+
pub mod exports;
78
pub use rustc_hir::def_id;
89
pub use rustc_hir::hir_id::*;
910
pub mod intravisit;

src/librustc/hir/def.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::hir;
2-
use crate::hir::def_id::{DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
3-
use crate::ty;
2+
use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
43

54
use rustc_macros::HashStable;
65
use rustc_span::hygiene::MacroKind;
7-
use rustc_span::Span;
86
use syntax::ast;
97
use syntax::ast::NodeId;
108

@@ -293,29 +291,6 @@ impl<T> PerNS<Option<T>> {
293291
}
294292
}
295293

296-
/// This is the replacement export map. It maps a module to all of the exports
297-
/// within.
298-
pub type ExportMap<Id> = DefIdMap<Vec<Export<Id>>>;
299-
300-
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
301-
pub struct Export<Id> {
302-
/// The name of the target.
303-
pub ident: ast::Ident,
304-
/// The resolution of the target.
305-
pub res: Res<Id>,
306-
/// The span of the target.
307-
pub span: Span,
308-
/// The visibility of the export.
309-
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
310-
pub vis: ty::Visibility,
311-
}
312-
313-
impl<Id> Export<Id> {
314-
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
315-
Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis }
316-
}
317-
}
318-
319294
impl CtorKind {
320295
pub fn from_ast(vdata: &ast::VariantData) -> CtorKind {
321296
match *vdata {

src/librustc/hir/exports.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::hir::def::Res;
2+
use crate::hir::def_id::DefIdMap;
3+
use crate::ty;
4+
5+
use rustc_macros::HashStable;
6+
use rustc_span::Span;
7+
use syntax::ast;
8+
9+
use std::fmt::Debug;
10+
11+
/// This is the replacement export map. It maps a module to all of the exports
12+
/// within.
13+
pub type ExportMap<Id> = DefIdMap<Vec<Export<Id>>>;
14+
15+
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
16+
pub struct Export<Id> {
17+
/// The name of the target.
18+
pub ident: ast::Ident,
19+
/// The resolution of the target.
20+
pub res: Res<Id>,
21+
/// The span of the target.
22+
pub span: Span,
23+
/// The visibility of the export.
24+
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
25+
pub vis: ty::Visibility,
26+
}
27+
28+
impl<Id> Export<Id> {
29+
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
30+
Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis }
31+
}
32+
}

src/librustc/ty/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use crate::arena::Arena;
44
use crate::dep_graph::DepGraph;
55
use crate::dep_graph::{self, DepConstructor, DepNode};
6-
use crate::hir::def::{DefKind, Export, Res};
6+
use crate::hir::def::{DefKind, Res};
77
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
8+
use crate::hir::exports::Export;
89
use crate::hir::map as hir_map;
910
use crate::hir::map::DefPathHash;
1011
use crate::hir::{self, HirId, Node, TraitCandidate};

src/librustc/ty/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub use self::BorrowKind::*;
66
pub use self::IntVarValue::*;
77
pub use self::Variance::*;
88

9-
use crate::hir::def::{CtorKind, CtorOf, DefKind, ExportMap, Res};
9+
use crate::hir::def::{CtorKind, CtorOf, DefKind, Res};
1010
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
11+
use crate::hir::exports::ExportMap;
1112
use crate::hir::Node;
1213
use crate::hir::{map as hir_map, GlobMap, TraitMap};
1314
use crate::ich::Fingerprint;

src/librustc/ty/query/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::dep_graph::{self, DepNode};
2-
use crate::hir::def::{DefKind, Export};
2+
use crate::hir::def::DefKind;
33
use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex};
4+
use crate::hir::exports::Export;
45
use crate::hir::{self, HirIdSet, ItemLocalId, TraitCandidate};
56
use crate::infer::canonical::{self, Canonical};
67
use crate::lint;

src/librustc_metadata/rmeta/decoder.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use crate::rmeta::*;
55

66
use rustc::dep_graph::{self, DepNodeIndex};
77
use rustc::hir;
8-
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, Res};
8+
use rustc::hir::def::{CtorKind, CtorOf, DefKind, Res};
99
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
10+
use rustc::hir::exports::Export;
1011
use rustc::hir::map::definitions::DefPathTable;
1112
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
1213
use rustc::middle::cstore::{CrateSource, ExternCrate};
@@ -930,7 +931,7 @@ impl<'a, 'tcx> CrateMetadata {
930931
/// Iterates over each child of the given item.
931932
fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
932933
where
933-
F: FnMut(def::Export<hir::HirId>),
934+
F: FnMut(Export<hir::HirId>),
934935
{
935936
if let Some(proc_macros_ids) = self.root.proc_macro_data.map(|d| d.decode(self)) {
936937
/* 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 {
944945
self.local_def_id(def_index),
945946
);
946947
let ident = Ident::from_str(raw_macro.name());
947-
callback(def::Export {
948-
ident: ident,
949-
res: res,
950-
vis: ty::Visibility::Public,
951-
span: DUMMY_SP,
952-
});
948+
callback(Export { ident, res, vis: ty::Visibility::Public, span: DUMMY_SP });
953949
}
954950
}
955951
return;
@@ -989,7 +985,7 @@ impl<'a, 'tcx> CrateMetadata {
989985
.unwrap_or(Lazy::empty());
990986
for child_index in child_children.decode((self, sess)) {
991987
if let Some(kind) = self.def_kind(child_index) {
992-
callback(def::Export {
988+
callback(Export {
993989
res: Res::Def(kind, self.local_def_id(child_index)),
994990
ident: Ident::with_dummy_span(self.item_name(child_index)),
995991
vis: self.get_visibility(child_index),
@@ -1019,7 +1015,7 @@ impl<'a, 'tcx> CrateMetadata {
10191015
let vis = self.get_visibility(child_index);
10201016
let def_id = self.local_def_id(child_index);
10211017
let res = Res::Def(kind, def_id);
1022-
callback(def::Export { res, ident, vis, span });
1018+
callback(Export { res, ident, vis, span });
10231019
// For non-re-export structs and variants add their constructors to children.
10241020
// Re-export lists automatically contain constructors when necessary.
10251021
match kind {
@@ -1029,7 +1025,7 @@ impl<'a, 'tcx> CrateMetadata {
10291025
let ctor_res =
10301026
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
10311027
let vis = self.get_visibility(ctor_def_id.index);
1032-
callback(def::Export { res: ctor_res, vis, ident, span });
1028+
callback(Export { res: ctor_res, vis, ident, span });
10331029
}
10341030
}
10351031
DefKind::Variant => {
@@ -1053,7 +1049,7 @@ impl<'a, 'tcx> CrateMetadata {
10531049
vis = ty::Visibility::Restricted(crate_def_id);
10541050
}
10551051
}
1056-
callback(def::Export { res: ctor_res, ident, vis, span });
1052+
callback(Export { res: ctor_res, ident, vis, span });
10571053
}
10581054
_ => {}
10591055
}

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::native_libs;
55
use crate::rmeta::{self, encoder};
66

77
use rustc::hir;
8-
use rustc::hir::def;
98
use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
9+
use rustc::hir::exports::Export;
1010
use rustc::hir::map::definitions::DefPathTable;
1111
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
1212
use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind};
@@ -342,29 +342,28 @@ pub fn provide(providers: &mut Providers<'_>) {
342342
// (restrict scope of mutable-borrow of `visible_parent_map`)
343343
{
344344
let visible_parent_map = &mut visible_parent_map;
345-
let mut add_child = |bfs_queue: &mut VecDeque<_>,
346-
child: &def::Export<hir::HirId>,
347-
parent: DefId| {
348-
if child.vis != ty::Visibility::Public {
349-
return;
350-
}
345+
let mut add_child =
346+
|bfs_queue: &mut VecDeque<_>, child: &Export<hir::HirId>, parent: DefId| {
347+
if child.vis != ty::Visibility::Public {
348+
return;
349+
}
351350

352-
if let Some(child) = child.res.opt_def_id() {
353-
match visible_parent_map.entry(child) {
354-
Entry::Occupied(mut entry) => {
355-
// If `child` is defined in crate `cnum`, ensure
356-
// that it is mapped to a parent in `cnum`.
357-
if child.krate == cnum && entry.get().krate != cnum {
351+
if let Some(child) = child.res.opt_def_id() {
352+
match visible_parent_map.entry(child) {
353+
Entry::Occupied(mut entry) => {
354+
// If `child` is defined in crate `cnum`, ensure
355+
// that it is mapped to a parent in `cnum`.
356+
if child.krate == cnum && entry.get().krate != cnum {
357+
entry.insert(parent);
358+
}
359+
}
360+
Entry::Vacant(entry) => {
358361
entry.insert(parent);
362+
bfs_queue.push_back(child);
359363
}
360364
}
361-
Entry::Vacant(entry) => {
362-
entry.insert(parent);
363-
bfs_queue.push_back(child);
364-
}
365365
}
366-
}
367-
};
366+
};
368367

369368
while let Some(def) = bfs_queue.pop_front() {
370369
for child in tcx.item_children(def).iter() {
@@ -410,7 +409,7 @@ impl CStore {
410409
&self,
411410
def_id: DefId,
412411
sess: &Session,
413-
) -> Vec<def::Export<hir::HirId>> {
412+
) -> Vec<Export<hir::HirId>> {
414413
let mut result = vec![];
415414
self.get_crate_data(def_id.krate).each_child_of_item(
416415
def_id.index,

src/librustc_metadata/rmeta/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use decoder::Metadata;
22
use table::{Table, TableBuilder};
33

44
use rustc::hir;
5-
use rustc::hir::def::{self, CtorKind};
5+
use rustc::hir::def::CtorKind;
66
use rustc::hir::def_id::{DefId, DefIndex};
7+
use rustc::hir::exports::Export;
78
use rustc::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLibrary};
89
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
910
use rustc::middle::lang_items;
@@ -317,7 +318,7 @@ struct RenderedConst(String);
317318

318319
#[derive(RustcEncodable, RustcDecodable)]
319320
struct ModData {
320-
reexports: Lazy<[def::Export<hir::HirId>]>,
321+
reexports: Lazy<[Export<hir::HirId>]>,
321322
}
322323

323324
#[derive(RustcEncodable, RustcDecodable)]

src/librustc_resolve/build_reduced_graph.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segmen
1919
use rustc::bug;
2020
use rustc::hir::def::{self, *};
2121
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
22+
use rustc::hir::exports::Export;
2223
use rustc::middle::cstore::CrateStore;
2324
use rustc::ty;
2425
use rustc_metadata::creader::LoadedMacro;

src/librustc_resolve/imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBindin
1313

1414
use errors::{pluralize, Applicability};
1515

16-
use rustc::hir::def::{self, Export, PartialRes};
16+
use rustc::hir::def::{self, PartialRes};
1717
use rustc::hir::def_id::DefId;
18+
use rustc::hir::exports::Export;
1819
use rustc::lint::builtin::BuiltinLintDiagnostics;
1920
use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS};
2021
use rustc::session::DiagnosticMessageId;

src/librustc_resolve/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use Determinacy::*;
2222

2323
use errors::{Applicability, DiagnosticBuilder};
2424
use rustc::hir::def::Namespace::*;
25-
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, ExportMap, NonMacroAttrKind, PartialRes};
25+
use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
2626
use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
27+
use rustc::hir::exports::ExportMap;
2728
use rustc::hir::map::Definitions;
2829
use rustc::hir::{Bool, Char, Float, Int, PrimTy, Str, Uint};
2930
use rustc::hir::{GlobMap, TraitMap};

0 commit comments

Comments
 (0)