Skip to content

Commit 173d5b3

Browse files
committed
Split up DefCollector::root().
1 parent 1ee64e4 commit 173d5b3

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/librustc/hir/map/def_collector.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,20 @@ pub struct DefCollector<'ast> {
3030
}
3131

3232
impl<'ast> DefCollector<'ast> {
33-
pub fn root(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
34-
let mut collector = DefCollector {
33+
pub fn new(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
34+
DefCollector {
3535
hir_crate: None,
3636
definitions: definitions,
3737
parent_def: None,
38-
};
39-
let root = collector.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
40-
assert_eq!(root, CRATE_DEF_INDEX);
41-
collector.parent_def = Some(root);
42-
43-
collector.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc);
44-
45-
collector
38+
}
4639
}
4740

4841
pub fn extend(parent_node: NodeId,
4942
parent_def_path: DefPath,
5043
parent_def_id: DefId,
5144
definitions: &'ast mut Definitions)
5245
-> DefCollector<'ast> {
53-
let mut collector = DefCollector {
54-
hir_crate: None,
55-
parent_def: None,
56-
definitions: definitions,
57-
};
46+
let mut collector = DefCollector::new(definitions);
5847

5948
assert_eq!(parent_def_path.krate, parent_def_id.krate);
6049
let root_path = Box::new(InlinedRootPath {
@@ -68,17 +57,21 @@ impl<'ast> DefCollector<'ast> {
6857
collector
6958
}
7059

60+
pub fn collect_root(&mut self) {
61+
let root = self.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
62+
assert_eq!(root, CRATE_DEF_INDEX);
63+
self.parent_def = Some(root);
64+
65+
self.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc);
66+
}
67+
7168
pub fn walk_item(&mut self, ii: &'ast InlinedItem, krate: &'ast hir::Crate) {
7269
self.hir_crate = Some(krate);
7370
ii.visit(self);
7471
}
7572

76-
fn parent_def(&self) -> Option<DefIndex> {
77-
self.parent_def
78-
}
79-
8073
fn create_def(&mut self, node_id: NodeId, data: DefPathData) -> DefIndex {
81-
let parent_def = self.parent_def();
74+
let parent_def = self.parent_def;
8275
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
8376
self.definitions.create_def_with_parent(parent_def, node_id, data)
8477
}

src/librustc/hir/map/definitions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ impl Definitions {
225225
}
226226

227227
pub fn collect(&mut self, krate: &ast::Crate) {
228-
let mut def_collector = DefCollector::root(self);
228+
let mut def_collector = DefCollector::new(self);
229+
def_collector.collect_root();
229230
visit::walk_crate(&mut def_collector, krate);
230231
}
231232

0 commit comments

Comments
 (0)