@@ -30,31 +30,20 @@ pub struct DefCollector<'ast> {
30
30
}
31
31
32
32
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 {
35
35
hir_crate : None ,
36
36
definitions : definitions,
37
37
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
+ }
46
39
}
47
40
48
41
pub fn extend ( parent_node : NodeId ,
49
42
parent_def_path : DefPath ,
50
43
parent_def_id : DefId ,
51
44
definitions : & ' ast mut Definitions )
52
45
-> 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) ;
58
47
59
48
assert_eq ! ( parent_def_path. krate, parent_def_id. krate) ;
60
49
let root_path = Box :: new ( InlinedRootPath {
@@ -68,17 +57,21 @@ impl<'ast> DefCollector<'ast> {
68
57
collector
69
58
}
70
59
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
+
71
68
pub fn walk_item ( & mut self , ii : & ' ast InlinedItem , krate : & ' ast hir:: Crate ) {
72
69
self . hir_crate = Some ( krate) ;
73
70
ii. visit ( self ) ;
74
71
}
75
72
76
- fn parent_def ( & self ) -> Option < DefIndex > {
77
- self . parent_def
78
- }
79
-
80
73
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 ;
82
75
debug ! ( "create_def(node_id={:?}, data={:?}, parent_def={:?})" , node_id, data, parent_def) ;
83
76
self . definitions . create_def_with_parent ( parent_def, node_id, data)
84
77
}
0 commit comments