@@ -9,7 +9,7 @@ use rustc_hir as hir;
9
9
use rustc_hir:: def:: { CtorKind , CtorOf , DefKind } ;
10
10
use rustc_hir:: def_id:: LocalDefId ;
11
11
use rustc_span:: hygiene:: LocalExpnId ;
12
- use rustc_span:: { Span , Symbol , kw , sym} ;
12
+ use rustc_span:: { Span , Symbol , sym} ;
13
13
use tracing:: debug;
14
14
15
15
use crate :: { ImplTraitContext , InvocationParent , Resolver } ;
@@ -38,7 +38,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
38
38
fn create_def (
39
39
& mut self ,
40
40
node_id : NodeId ,
41
- name : Symbol ,
41
+ name : Option < Symbol > ,
42
42
def_kind : DefKind ,
43
43
span : Span ,
44
44
) -> LocalDefId {
@@ -89,7 +89,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
89
89
self . visit_macro_invoc ( field. id ) ;
90
90
} else {
91
91
let name = field. ident . map_or_else ( || sym:: integer ( index ( self ) ) , |ident| ident. name ) ;
92
- let def = self . create_def ( field. id , name, DefKind :: Field , field. span ) ;
92
+ let def = self . create_def ( field. id , Some ( name) , DefKind :: Field , field. span ) ;
93
93
self . with_parent ( def, |this| visit:: walk_field_def ( this, field) ) ;
94
94
}
95
95
}
@@ -161,7 +161,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
161
161
return self . visit_macro_invoc ( i. id ) ;
162
162
}
163
163
} ;
164
- let def_id = self . create_def ( i. id , i. ident . name , def_kind, i. span ) ;
164
+ let def_id = self . create_def ( i. id , Some ( i. ident . name ) , def_kind, i. span ) ;
165
165
166
166
if let Some ( macro_data) = opt_macro_data {
167
167
self . resolver . macro_map . insert ( def_id. to_def_id ( ) , macro_data) ;
@@ -175,7 +175,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
175
175
if let Some ( ( ctor_kind, ctor_node_id) ) = CtorKind :: from_ast ( struct_def) {
176
176
this. create_def (
177
177
ctor_node_id,
178
- kw :: Empty ,
178
+ None ,
179
179
DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) ,
180
180
i. span ,
181
181
) ;
@@ -211,20 +211,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
211
211
}
212
212
213
213
let ( return_id, return_span) = coroutine_kind. return_id ( ) ;
214
- let return_def =
215
- self . create_def ( return_id, kw:: Empty , DefKind :: OpaqueTy , return_span) ;
214
+ let return_def = self . create_def ( return_id, None , DefKind :: OpaqueTy , return_span) ;
216
215
self . with_parent ( return_def, |this| this. visit_fn_ret_ty ( output) ) ;
217
216
218
217
// If this async fn has no body (i.e. it's an async fn signature in a trait)
219
218
// then the closure_def will never be used, and we should avoid generating a
220
219
// def-id for it.
221
220
if let Some ( body) = body {
222
- let closure_def = self . create_def (
223
- coroutine_kind. closure_id ( ) ,
224
- kw:: Empty ,
225
- DefKind :: Closure ,
226
- span,
227
- ) ;
221
+ let closure_def =
222
+ self . create_def ( coroutine_kind. closure_id ( ) , None , DefKind :: Closure , span) ;
228
223
self . with_parent ( closure_def, |this| this. visit_block ( body) ) ;
229
224
}
230
225
}
@@ -235,15 +230,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
235
230
// Async closures desugar to closures inside of closures, so
236
231
// we must create two defs.
237
232
let coroutine_def =
238
- self . create_def ( coroutine_kind. closure_id ( ) , kw :: Empty , DefKind :: Closure , span) ;
233
+ self . create_def ( coroutine_kind. closure_id ( ) , None , DefKind :: Closure , span) ;
239
234
self . with_parent ( coroutine_def, |this| this. visit_expr ( body) ) ;
240
235
}
241
236
_ => visit:: walk_fn ( self , fn_kind) ,
242
237
}
243
238
}
244
239
245
240
fn visit_use_tree ( & mut self , use_tree : & ' a UseTree , id : NodeId , _nested : bool ) {
246
- self . create_def ( id, kw :: Empty , DefKind :: Use , use_tree. span ) ;
241
+ self . create_def ( id, None , DefKind :: Use , use_tree. span ) ;
247
242
visit:: walk_use_tree ( self , use_tree, id) ;
248
243
}
249
244
@@ -262,7 +257,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
262
257
ForeignItemKind :: MacCall ( _) => return self . visit_macro_invoc ( fi. id ) ,
263
258
} ;
264
259
265
- let def = self . create_def ( fi. id , fi. ident . name , def_kind, fi. span ) ;
260
+ let def = self . create_def ( fi. id , Some ( fi. ident . name ) , def_kind, fi. span ) ;
266
261
267
262
self . with_parent ( def, |this| visit:: walk_item ( this, fi) ) ;
268
263
}
@@ -271,12 +266,12 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
271
266
if v. is_placeholder {
272
267
return self . visit_macro_invoc ( v. id ) ;
273
268
}
274
- let def = self . create_def ( v. id , v. ident . name , DefKind :: Variant , v. span ) ;
269
+ let def = self . create_def ( v. id , Some ( v. ident . name ) , DefKind :: Variant , v. span ) ;
275
270
self . with_parent ( def, |this| {
276
271
if let Some ( ( ctor_kind, ctor_node_id) ) = CtorKind :: from_ast ( & v. data ) {
277
272
this. create_def (
278
273
ctor_node_id,
279
- kw :: Empty ,
274
+ None ,
280
275
DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) ,
281
276
v. span ,
282
277
) ;
@@ -312,7 +307,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
312
307
GenericParamKind :: Type { .. } => DefKind :: TyParam ,
313
308
GenericParamKind :: Const { .. } => DefKind :: ConstParam ,
314
309
} ;
315
- self . create_def ( param. id , param. ident . name , def_kind, param. ident . span ) ;
310
+ self . create_def ( param. id , Some ( param. ident . name ) , def_kind, param. ident . span ) ;
316
311
317
312
// impl-Trait can happen inside generic parameters, like
318
313
// ```
@@ -335,7 +330,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
335
330
}
336
331
} ;
337
332
338
- let def = self . create_def ( i. id , i. ident . name , def_kind, i. span ) ;
333
+ let def = self . create_def ( i. id , Some ( i. ident . name ) , def_kind, i. span ) ;
339
334
self . with_parent ( def, |this| visit:: walk_assoc_item ( this, i, ctxt) ) ;
340
335
}
341
336
@@ -347,27 +342,22 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
347
342
}
348
343
349
344
fn visit_anon_const ( & mut self , constant : & ' a AnonConst ) {
350
- let parent =
351
- self . create_def ( constant. id , kw:: Empty , DefKind :: AnonConst , constant. value . span ) ;
345
+ let parent = self . create_def ( constant. id , None , DefKind :: AnonConst , constant. value . span ) ;
352
346
self . with_parent ( parent, |this| visit:: walk_anon_const ( this, constant) ) ;
353
347
}
354
348
355
349
fn visit_expr ( & mut self , expr : & ' a Expr ) {
356
350
let parent_def = match expr. kind {
357
351
ExprKind :: MacCall ( ..) => return self . visit_macro_invoc ( expr. id ) ,
358
352
ExprKind :: Closure ( ..) | ExprKind :: Gen ( ..) => {
359
- self . create_def ( expr. id , kw :: Empty , DefKind :: Closure , expr. span )
353
+ self . create_def ( expr. id , None , DefKind :: Closure , expr. span )
360
354
}
361
355
ExprKind :: ConstBlock ( ref constant) => {
362
356
for attr in & expr. attrs {
363
357
visit:: walk_attribute ( self , attr) ;
364
358
}
365
- let def = self . create_def (
366
- constant. id ,
367
- kw:: Empty ,
368
- DefKind :: InlineConst ,
369
- constant. value . span ,
370
- ) ;
359
+ let def =
360
+ self . create_def ( constant. id , None , DefKind :: InlineConst , constant. value . span ) ;
371
361
self . with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
372
362
return ;
373
363
}
@@ -391,7 +381,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
391
381
ImplTraitContext :: Existential => DefKind :: OpaqueTy ,
392
382
ImplTraitContext :: InBinding => return visit:: walk_ty ( self , ty) ,
393
383
} ;
394
- let id = self . create_def ( * id, name, kind, ty. span ) ;
384
+ let id = self . create_def ( * id, Some ( name) , kind, ty. span ) ;
395
385
match self . impl_trait_context {
396
386
// Do not nest APIT, as we desugar them as `impl_trait: bounds`,
397
387
// so the `impl_trait` node is not a parent to `bounds`.
@@ -495,7 +485,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
495
485
InlineAsmOperand :: Const { anon_const } => {
496
486
let def = self . create_def (
497
487
anon_const. id ,
498
- kw :: Empty ,
488
+ None ,
499
489
DefKind :: InlineConst ,
500
490
anon_const. value . span ,
501
491
) ;
0 commit comments