@@ -18,6 +18,7 @@ use syntax::visit;
18
18
use syntax:: symbol:: keywords;
19
19
use syntax:: symbol:: Symbol ;
20
20
use syntax:: parse:: token:: { self , Token } ;
21
+ use syntax_pos:: Span ;
21
22
22
23
use hir:: map:: { ITEM_LIKE_SPACE , REGULAR_SPACE } ;
23
24
@@ -57,12 +58,13 @@ impl<'a> DefCollector<'a> {
57
58
fn create_def ( & mut self ,
58
59
node_id : NodeId ,
59
60
data : DefPathData ,
60
- address_space : DefIndexAddressSpace )
61
+ address_space : DefIndexAddressSpace ,
62
+ span : Span )
61
63
-> DefIndex {
62
64
let parent_def = self . parent_def . unwrap ( ) ;
63
65
debug ! ( "create_def(node_id={:?}, data={:?}, parent_def={:?})" , node_id, data, parent_def) ;
64
66
self . definitions
65
- . create_def_with_parent ( parent_def, node_id, data, address_space, self . expansion )
67
+ . create_def_with_parent ( parent_def, node_id, data, address_space, self . expansion , span )
66
68
}
67
69
68
70
pub fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_def : DefIndex , f : F ) {
@@ -83,7 +85,7 @@ impl<'a> DefCollector<'a> {
83
85
_ => { }
84
86
}
85
87
86
- self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE ) ;
88
+ self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE , expr . span ) ;
87
89
}
88
90
89
91
fn visit_macro_invoc ( & mut self , id : NodeId , const_expr : bool ) {
@@ -122,7 +124,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
122
124
return visit:: walk_item ( self , i) ;
123
125
}
124
126
} ;
125
- let def = self . create_def ( i. id , def_data, ITEM_LIKE_SPACE ) ;
127
+ let def = self . create_def ( i. id , def_data, ITEM_LIKE_SPACE , i . span ) ;
126
128
127
129
self . with_parent ( def, |this| {
128
130
match i. node {
@@ -131,14 +133,16 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
131
133
let variant_def_index =
132
134
this. create_def ( v. node . data . id ( ) ,
133
135
DefPathData :: EnumVariant ( v. node . name . name . as_str ( ) ) ,
134
- REGULAR_SPACE ) ;
136
+ REGULAR_SPACE ,
137
+ v. span ) ;
135
138
this. with_parent ( variant_def_index, |this| {
136
139
for ( index, field) in v. node . data . fields ( ) . iter ( ) . enumerate ( ) {
137
140
let name = field. ident . map ( |ident| ident. name )
138
141
. unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
139
142
this. create_def ( field. id ,
140
143
DefPathData :: Field ( name. as_str ( ) ) ,
141
- REGULAR_SPACE ) ;
144
+ REGULAR_SPACE ,
145
+ field. span ) ;
142
146
}
143
147
144
148
if let Some ( ref expr) = v. node . disr_expr {
@@ -152,13 +156,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
152
156
if !struct_def. is_struct ( ) {
153
157
this. create_def ( struct_def. id ( ) ,
154
158
DefPathData :: StructCtor ,
155
- REGULAR_SPACE ) ;
159
+ REGULAR_SPACE ,
160
+ i. span ) ;
156
161
}
157
162
158
163
for ( index, field) in struct_def. fields ( ) . iter ( ) . enumerate ( ) {
159
164
let name = field. ident . map ( |ident| ident. name )
160
165
. unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
161
- this. create_def ( field. id , DefPathData :: Field ( name. as_str ( ) ) , REGULAR_SPACE ) ;
166
+ this. create_def ( field. id ,
167
+ DefPathData :: Field ( name. as_str ( ) ) ,
168
+ REGULAR_SPACE ,
169
+ field. span ) ;
162
170
}
163
171
}
164
172
_ => { }
@@ -168,14 +176,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
168
176
}
169
177
170
178
fn visit_use_tree ( & mut self , use_tree : & ' a UseTree , id : NodeId , _nested : bool ) {
171
- self . create_def ( id, DefPathData :: Misc , ITEM_LIKE_SPACE ) ;
179
+ self . create_def ( id, DefPathData :: Misc , ITEM_LIKE_SPACE , use_tree . span ) ;
172
180
visit:: walk_use_tree ( self , use_tree, id) ;
173
181
}
174
182
175
183
fn visit_foreign_item ( & mut self , foreign_item : & ' a ForeignItem ) {
176
184
let def = self . create_def ( foreign_item. id ,
177
185
DefPathData :: ValueNs ( foreign_item. ident . name . as_str ( ) ) ,
178
- REGULAR_SPACE ) ;
186
+ REGULAR_SPACE ,
187
+ foreign_item. span ) ;
179
188
180
189
self . with_parent ( def, |this| {
181
190
visit:: walk_foreign_item ( this, foreign_item) ;
@@ -188,14 +197,16 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
188
197
self . create_def (
189
198
lifetime_def. lifetime . id ,
190
199
DefPathData :: LifetimeDef ( lifetime_def. lifetime . ident . name . as_str ( ) ) ,
191
- REGULAR_SPACE
200
+ REGULAR_SPACE ,
201
+ lifetime_def. lifetime . span
192
202
) ;
193
203
}
194
204
GenericParam :: Type ( ref ty_param) => {
195
205
self . create_def (
196
206
ty_param. id ,
197
207
DefPathData :: TypeParam ( ty_param. ident . name . as_str ( ) ) ,
198
- REGULAR_SPACE
208
+ REGULAR_SPACE ,
209
+ ty_param. span
199
210
) ;
200
211
}
201
212
}
@@ -211,7 +222,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
211
222
TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id , false ) ,
212
223
} ;
213
224
214
- let def = self . create_def ( ti. id , def_data, ITEM_LIKE_SPACE ) ;
225
+ let def = self . create_def ( ti. id , def_data, ITEM_LIKE_SPACE , ti . span ) ;
215
226
self . with_parent ( def, |this| {
216
227
if let TraitItemKind :: Const ( _, Some ( ref expr) ) = ti. node {
217
228
this. visit_const_expr ( expr) ;
@@ -229,7 +240,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
229
240
ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id , false ) ,
230
241
} ;
231
242
232
- let def = self . create_def ( ii. id , def_data, ITEM_LIKE_SPACE ) ;
243
+ let def = self . create_def ( ii. id , def_data, ITEM_LIKE_SPACE , ii . span ) ;
233
244
self . with_parent ( def, |this| {
234
245
if let ImplItemKind :: Const ( _, ref expr) = ii. node {
235
246
this. visit_const_expr ( expr) ;
@@ -255,7 +266,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
255
266
ExprKind :: Closure ( ..) => {
256
267
let def = self . create_def ( expr. id ,
257
268
DefPathData :: ClosureExpr ,
258
- REGULAR_SPACE ) ;
269
+ REGULAR_SPACE ,
270
+ expr. span ) ;
259
271
self . parent_def = Some ( def) ;
260
272
}
261
273
_ => { }
@@ -270,7 +282,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
270
282
TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
271
283
TyKind :: Array ( _, ref length) => self . visit_const_expr ( length) ,
272
284
TyKind :: ImplTrait ( ..) => {
273
- self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE ) ;
285
+ self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE , ty . span ) ;
274
286
}
275
287
TyKind :: Typeof ( ref expr) => self . visit_const_expr ( expr) ,
276
288
_ => { }
0 commit comments