9
9
// except according to those terms.
10
10
11
11
use hir:: map:: definitions:: * ;
12
- use hir:: def_id:: { CRATE_DEF_INDEX , DefIndex } ;
12
+ use hir:: def_id:: { CRATE_DEF_INDEX , DefIndex , DefIndexAddressSpace } ;
13
13
14
14
use syntax:: ast:: * ;
15
15
use syntax:: ext:: hygiene:: Mark ;
16
16
use syntax:: visit;
17
17
use syntax:: symbol:: { Symbol , keywords} ;
18
18
19
+ use hir:: map:: { ITEM_LIKE_SPACE , REGULAR_SPACE } ;
20
+
19
21
/// Creates def ids for nodes in the AST.
20
22
pub struct DefCollector < ' a > {
21
23
definitions : & ' a mut Definitions ,
@@ -39,23 +41,31 @@ impl<'a> DefCollector<'a> {
39
41
}
40
42
41
43
pub fn collect_root ( & mut self ) {
42
- let root = self . create_def_with_parent ( None , CRATE_NODE_ID , DefPathData :: CrateRoot ) ;
44
+ let root = self . create_def_with_parent ( None ,
45
+ CRATE_NODE_ID ,
46
+ DefPathData :: CrateRoot ,
47
+ ITEM_LIKE_SPACE ) ;
43
48
assert_eq ! ( root, CRATE_DEF_INDEX ) ;
44
49
self . parent_def = Some ( root) ;
45
50
}
46
51
47
- fn create_def ( & mut self , node_id : NodeId , data : DefPathData ) -> DefIndex {
52
+ fn create_def ( & mut self ,
53
+ node_id : NodeId ,
54
+ data : DefPathData ,
55
+ address_space : DefIndexAddressSpace )
56
+ -> DefIndex {
48
57
let parent_def = self . parent_def ;
49
58
debug ! ( "create_def(node_id={:?}, data={:?}, parent_def={:?})" , node_id, data, parent_def) ;
50
- self . definitions . create_def_with_parent ( parent_def, node_id, data)
59
+ self . definitions . create_def_with_parent ( parent_def, node_id, data, address_space )
51
60
}
52
61
53
62
fn create_def_with_parent ( & mut self ,
54
63
parent : Option < DefIndex > ,
55
64
node_id : NodeId ,
56
- data : DefPathData )
65
+ data : DefPathData ,
66
+ address_space : DefIndexAddressSpace )
57
67
-> DefIndex {
58
- self . definitions . create_def_with_parent ( parent, node_id, data)
68
+ self . definitions . create_def_with_parent ( parent, node_id, data, address_space )
59
69
}
60
70
61
71
pub fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_def : DefIndex , f : F ) {
@@ -76,7 +86,7 @@ impl<'a> DefCollector<'a> {
76
86
_ => { }
77
87
}
78
88
79
- self . create_def ( expr. id , DefPathData :: Initializer ) ;
89
+ self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE ) ;
80
90
}
81
91
82
92
fn visit_macro_invoc ( & mut self , id : NodeId , const_expr : bool ) {
@@ -118,27 +128,32 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
118
128
ViewPathSimple ( ..) => { }
119
129
ViewPathList ( _, ref imports) => {
120
130
for import in imports {
121
- self . create_def ( import. node . id , DefPathData :: Misc ) ;
131
+ self . create_def ( import. node . id ,
132
+ DefPathData :: Misc ,
133
+ ITEM_LIKE_SPACE ) ;
122
134
}
123
135
}
124
136
}
125
137
DefPathData :: Misc
126
138
}
127
139
} ;
128
- let def = self . create_def ( i. id , def_data) ;
140
+ let def = self . create_def ( i. id , def_data, ITEM_LIKE_SPACE ) ;
129
141
130
142
self . with_parent ( def, |this| {
131
143
match i. node {
132
144
ItemKind :: Enum ( ref enum_definition, _) => {
133
145
for v in & enum_definition. variants {
134
146
let variant_def_index =
135
147
this. create_def ( v. node . data . id ( ) ,
136
- DefPathData :: EnumVariant ( v. node . name . name . as_str ( ) ) ) ;
148
+ DefPathData :: EnumVariant ( v. node . name . name . as_str ( ) ) ,
149
+ REGULAR_SPACE ) ;
137
150
this. with_parent ( variant_def_index, |this| {
138
151
for ( index, field) in v. node . data . fields ( ) . iter ( ) . enumerate ( ) {
139
152
let name = field. ident . map ( |ident| ident. name )
140
153
. unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
141
- this. create_def ( field. id , DefPathData :: Field ( name. as_str ( ) ) ) ;
154
+ this. create_def ( field. id ,
155
+ DefPathData :: Field ( name. as_str ( ) ) ,
156
+ REGULAR_SPACE ) ;
142
157
}
143
158
144
159
if let Some ( ref expr) = v. node . disr_expr {
@@ -151,13 +166,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
151
166
// If this is a tuple-like struct, register the constructor.
152
167
if !struct_def. is_struct ( ) {
153
168
this. create_def ( struct_def. id ( ) ,
154
- DefPathData :: StructCtor ) ;
169
+ DefPathData :: StructCtor ,
170
+ REGULAR_SPACE ) ;
155
171
}
156
172
157
173
for ( index, field) in struct_def. fields ( ) . iter ( ) . enumerate ( ) {
158
174
let name = field. ident . map ( |ident| ident. name . as_str ( ) )
159
175
. unwrap_or ( Symbol :: intern ( & index. to_string ( ) ) . as_str ( ) ) ;
160
- this. create_def ( field. id , DefPathData :: Field ( name) ) ;
176
+ this. create_def ( field. id , DefPathData :: Field ( name) , REGULAR_SPACE ) ;
161
177
}
162
178
}
163
179
_ => { }
@@ -168,7 +184,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
168
184
169
185
fn visit_foreign_item ( & mut self , foreign_item : & ' a ForeignItem ) {
170
186
let def = self . create_def ( foreign_item. id ,
171
- DefPathData :: ValueNs ( foreign_item. ident . name . as_str ( ) ) ) ;
187
+ DefPathData :: ValueNs ( foreign_item. ident . name . as_str ( ) ) ,
188
+ REGULAR_SPACE ) ;
172
189
173
190
self . with_parent ( def, |this| {
174
191
visit:: walk_foreign_item ( this, foreign_item) ;
@@ -177,7 +194,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
177
194
178
195
fn visit_generics ( & mut self , generics : & ' a Generics ) {
179
196
for ty_param in generics. ty_params . iter ( ) {
180
- self . create_def ( ty_param. id , DefPathData :: TypeParam ( ty_param. ident . name . as_str ( ) ) ) ;
197
+ self . create_def ( ty_param. id ,
198
+ DefPathData :: TypeParam ( ty_param. ident . name . as_str ( ) ) ,
199
+ REGULAR_SPACE ) ;
181
200
}
182
201
183
202
visit:: walk_generics ( self , generics) ;
@@ -191,7 +210,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
191
210
TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id , false ) ,
192
211
} ;
193
212
194
- let def = self . create_def ( ti. id , def_data) ;
213
+ let def = self . create_def ( ti. id , def_data, ITEM_LIKE_SPACE ) ;
195
214
self . with_parent ( def, |this| {
196
215
if let TraitItemKind :: Const ( _, Some ( ref expr) ) = ti. node {
197
216
this. visit_const_expr ( expr) ;
@@ -209,7 +228,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
209
228
ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id , false ) ,
210
229
} ;
211
230
212
- let def = self . create_def ( ii. id , def_data) ;
231
+ let def = self . create_def ( ii. id , def_data, ITEM_LIKE_SPACE ) ;
213
232
self . with_parent ( def, |this| {
214
233
if let ImplItemKind :: Const ( _, ref expr) = ii. node {
215
234
this. visit_const_expr ( expr) ;
@@ -225,7 +244,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
225
244
match pat. node {
226
245
PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id , false ) ,
227
246
PatKind :: Ident ( _, id, _) => {
228
- let def = self . create_def ( pat. id , DefPathData :: Binding ( id. node . name . as_str ( ) ) ) ;
247
+ let def = self . create_def ( pat. id ,
248
+ DefPathData :: Binding ( id. node . name . as_str ( ) ) ,
249
+ REGULAR_SPACE ) ;
229
250
self . parent_def = Some ( def) ;
230
251
}
231
252
_ => { }
@@ -242,7 +263,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
242
263
ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , false ) ,
243
264
ExprKind :: Repeat ( _, ref count) => self . visit_const_expr ( count) ,
244
265
ExprKind :: Closure ( ..) => {
245
- let def = self . create_def ( expr. id , DefPathData :: ClosureExpr ) ;
266
+ let def = self . create_def ( expr. id ,
267
+ DefPathData :: ClosureExpr ,
268
+ REGULAR_SPACE ) ;
246
269
self . parent_def = Some ( def) ;
247
270
}
248
271
_ => { }
@@ -257,7 +280,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
257
280
TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
258
281
TyKind :: Array ( _, ref length) => self . visit_const_expr ( length) ,
259
282
TyKind :: ImplTrait ( ..) => {
260
- self . create_def ( ty. id , DefPathData :: ImplTrait ) ;
283
+ self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE ) ;
261
284
}
262
285
TyKind :: Typeof ( ref expr) => self . visit_const_expr ( expr) ,
263
286
_ => { }
@@ -266,7 +289,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
266
289
}
267
290
268
291
fn visit_lifetime_def ( & mut self , def : & ' a LifetimeDef ) {
269
- self . create_def ( def. lifetime . id , DefPathData :: LifetimeDef ( def. lifetime . name . as_str ( ) ) ) ;
292
+ self . create_def ( def. lifetime . id ,
293
+ DefPathData :: LifetimeDef ( def. lifetime . name . as_str ( ) ) ,
294
+ REGULAR_SPACE ) ;
270
295
}
271
296
272
297
fn visit_stmt ( & mut self , stmt : & ' a Stmt ) {
0 commit comments