@@ -111,6 +111,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
111
111
}
112
112
113
113
fn lower_foreign_item ( & mut self , item : & ForeignItem ) {
114
+ debug_assert_ne ! ( item. ident. name, kw:: Empty ) ;
114
115
self . with_lctx ( item. id , |lctx| hir:: OwnerNode :: ForeignItem ( lctx. lower_foreign_item ( item) ) )
115
116
}
116
117
}
@@ -154,14 +155,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
154
155
}
155
156
156
157
fn lower_item ( & mut self , i : & Item ) -> & ' hir hir:: Item < ' hir > {
157
- let mut ident = i. ident ;
158
158
let vis_span = self . lower_span ( i. vis . span ) ;
159
159
let hir_id = hir:: HirId :: make_owner ( self . current_hir_id_owner . def_id ) ;
160
160
let attrs = self . lower_attrs ( hir_id, & i. attrs , i. span ) ;
161
- let kind = self . lower_item_kind ( i. span , i. id , hir_id, & mut ident, attrs, vis_span, & i. kind ) ;
161
+ let kind = self . lower_item_kind ( i. span , i. id , hir_id, i . ident , attrs, vis_span, & i. kind ) ;
162
162
let item = hir:: Item {
163
163
owner_id : hir_id. expect_owner ( ) ,
164
- ident : self . lower_ident ( ident) ,
165
164
kind,
166
165
vis_span,
167
166
span : self . lower_span ( i. span ) ,
@@ -174,25 +173,34 @@ impl<'hir> LoweringContext<'_, 'hir> {
174
173
span : Span ,
175
174
id : NodeId ,
176
175
hir_id : hir:: HirId ,
177
- ident : & mut Ident ,
176
+ ident : Ident ,
178
177
attrs : & ' hir [ hir:: Attribute ] ,
179
178
vis_span : Span ,
180
179
i : & ItemKind ,
181
180
) -> hir:: ItemKind < ' hir > {
182
181
match i {
183
- ItemKind :: ExternCrate ( orig_name) => hir:: ItemKind :: ExternCrate ( * orig_name) ,
182
+ ItemKind :: ExternCrate ( orig_name) => {
183
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
184
+ let ident = self . lower_ident ( ident) ;
185
+ hir:: ItemKind :: ExternCrate ( * orig_name, ident)
186
+ }
184
187
ItemKind :: Use ( use_tree) => {
188
+ debug_assert_eq ! ( ident. name, kw:: Empty ) ;
185
189
// Start with an empty prefix.
186
190
let prefix = Path { segments : ThinVec :: new ( ) , span : use_tree. span , tokens : None } ;
187
191
188
- self . lower_use_tree ( use_tree, & prefix, id, vis_span, ident , attrs)
192
+ self . lower_use_tree ( use_tree, & prefix, id, vis_span, attrs)
189
193
}
190
194
ItemKind :: Static ( box ast:: StaticItem { ty : t, safety : _, mutability : m, expr : e } ) => {
195
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
196
+ let ident = self . lower_ident ( ident) ;
191
197
let ( ty, body_id) =
192
198
self . lower_const_item ( t, span, e. as_deref ( ) , ImplTraitPosition :: StaticTy ) ;
193
- hir:: ItemKind :: Static ( ty, * m, body_id)
199
+ hir:: ItemKind :: Static ( ident , ty, * m, body_id)
194
200
}
195
201
ItemKind :: Const ( box ast:: ConstItem { generics, ty, expr, .. } ) => {
202
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
203
+ let ident = self . lower_ident ( ident) ;
196
204
let ( generics, ( ty, body_id) ) = self . lower_generics (
197
205
generics,
198
206
id,
@@ -201,7 +209,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
201
209
this. lower_const_item ( ty, span, expr. as_deref ( ) , ImplTraitPosition :: ConstTy )
202
210
} ,
203
211
) ;
204
- hir:: ItemKind :: Const ( ty, generics, body_id)
212
+ hir:: ItemKind :: Const ( ident , ty, generics, body_id)
205
213
}
206
214
ItemKind :: Fn ( box Fn {
207
215
sig : FnSig { decl, header, span : fn_sig_span } ,
@@ -211,6 +219,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
211
219
define_opaque,
212
220
..
213
221
} ) => {
222
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
214
223
self . with_new_scopes ( * fn_sig_span, |this| {
215
224
// Note: we don't need to change the return type from `T` to
216
225
// `impl Future<Output = T>` here because lower_body
@@ -238,28 +247,44 @@ impl<'hir> LoweringContext<'_, 'hir> {
238
247
span : this. lower_span ( * fn_sig_span) ,
239
248
} ;
240
249
this. lower_define_opaque ( hir_id, & define_opaque) ;
241
- hir:: ItemKind :: Fn { sig, generics, body : body_id, has_body : body. is_some ( ) }
250
+ let ident = this. lower_ident ( ident) ;
251
+ hir:: ItemKind :: Fn {
252
+ ident,
253
+ sig,
254
+ generics,
255
+ body : body_id,
256
+ has_body : body. is_some ( ) ,
257
+ }
242
258
} )
243
259
}
244
- ItemKind :: Mod ( _, mod_kind) => match mod_kind {
245
- ModKind :: Loaded ( items, _, spans, _) => {
246
- hir:: ItemKind :: Mod ( self . lower_mod ( items, spans) )
260
+ ItemKind :: Mod ( _, mod_kind) => {
261
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
262
+ let ident = self . lower_ident ( ident) ;
263
+ match mod_kind {
264
+ ModKind :: Loaded ( items, _, spans, _) => {
265
+ hir:: ItemKind :: Mod ( ident, self . lower_mod ( items, spans) )
266
+ }
267
+ ModKind :: Unloaded => panic ! ( "`mod` items should have been loaded by now" ) ,
247
268
}
248
- ModKind :: Unloaded => panic ! ( "`mod` items should have been loaded by now" ) ,
249
- } ,
250
- ItemKind :: ForeignMod ( fm) => hir:: ItemKind :: ForeignMod {
251
- abi : fm. abi . map_or ( ExternAbi :: FALLBACK , |abi| self . lower_abi ( abi) ) ,
252
- items : self
253
- . arena
254
- . alloc_from_iter ( fm. items . iter ( ) . map ( |x| self . lower_foreign_item_ref ( x) ) ) ,
255
- } ,
269
+ }
270
+ ItemKind :: ForeignMod ( fm) => {
271
+ debug_assert_eq ! ( ident. name, kw:: Empty ) ;
272
+ hir:: ItemKind :: ForeignMod {
273
+ abi : fm. abi . map_or ( ExternAbi :: FALLBACK , |abi| self . lower_abi ( abi) ) ,
274
+ items : self
275
+ . arena
276
+ . alloc_from_iter ( fm. items . iter ( ) . map ( |x| self . lower_foreign_item_ref ( x) ) ) ,
277
+ }
278
+ }
256
279
ItemKind :: GlobalAsm ( asm) => {
280
+ debug_assert_eq ! ( ident. name, kw:: Empty ) ;
257
281
let asm = self . lower_inline_asm ( span, asm) ;
258
282
let fake_body =
259
283
self . lower_body ( |this| ( & [ ] , this. expr ( span, hir:: ExprKind :: InlineAsm ( asm) ) ) ) ;
260
284
hir:: ItemKind :: GlobalAsm { asm, fake_body }
261
285
}
262
286
ItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty, .. } ) => {
287
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
263
288
// We lower
264
289
//
265
290
// type Foo = impl Trait
@@ -268,6 +293,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
268
293
//
269
294
// type Foo = Foo1
270
295
// opaque type Foo1: Trait
296
+ let ident = self . lower_ident ( ident) ;
271
297
let mut generics = generics. clone ( ) ;
272
298
add_ty_alias_where_clause ( & mut generics, * where_clauses, true ) ;
273
299
let ( generics, ty) = self . lower_generics (
@@ -293,9 +319,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
293
319
) ,
294
320
} ,
295
321
) ;
296
- hir:: ItemKind :: TyAlias ( ty, generics)
322
+ hir:: ItemKind :: TyAlias ( ident , ty, generics)
297
323
}
298
324
ItemKind :: Enum ( enum_definition, generics) => {
325
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
326
+ let ident = self . lower_ident ( ident) ;
299
327
let ( generics, variants) = self . lower_generics (
300
328
generics,
301
329
id,
@@ -306,25 +334,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
306
334
)
307
335
} ,
308
336
) ;
309
- hir:: ItemKind :: Enum ( hir:: EnumDef { variants } , generics)
337
+ hir:: ItemKind :: Enum ( ident , hir:: EnumDef { variants } , generics)
310
338
}
311
339
ItemKind :: Struct ( struct_def, generics) => {
340
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
341
+ let ident = self . lower_ident ( ident) ;
312
342
let ( generics, struct_def) = self . lower_generics (
313
343
generics,
314
344
id,
315
345
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
316
346
|this| this. lower_variant_data ( hir_id, struct_def) ,
317
347
) ;
318
- hir:: ItemKind :: Struct ( struct_def, generics)
348
+ hir:: ItemKind :: Struct ( ident , struct_def, generics)
319
349
}
320
350
ItemKind :: Union ( vdata, generics) => {
351
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
352
+ let ident = self . lower_ident ( ident) ;
321
353
let ( generics, vdata) = self . lower_generics (
322
354
generics,
323
355
id,
324
356
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
325
357
|this| this. lower_variant_data ( hir_id, vdata) ,
326
358
) ;
327
- hir:: ItemKind :: Union ( vdata, generics)
359
+ hir:: ItemKind :: Union ( ident , vdata, generics)
328
360
}
329
361
ItemKind :: Impl ( box Impl {
330
362
safety,
@@ -336,6 +368,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
336
368
self_ty : ty,
337
369
items : impl_items,
338
370
} ) => {
371
+ debug_assert_eq ! ( ident. name, kw:: Empty ) ;
339
372
// Lower the "impl header" first. This ordering is important
340
373
// for in-band lifetimes! Consider `'a` here:
341
374
//
@@ -401,6 +434,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
401
434
} ) )
402
435
}
403
436
ItemKind :: Trait ( box Trait { is_auto, safety, generics, bounds, items } ) => {
437
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
438
+ let ident = self . lower_ident ( ident) ;
404
439
let ( generics, ( safety, items, bounds) ) = self . lower_generics (
405
440
generics,
406
441
id,
@@ -417,9 +452,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
417
452
( safety, items, bounds)
418
453
} ,
419
454
) ;
420
- hir:: ItemKind :: Trait ( * is_auto, safety, generics, bounds, items)
455
+ hir:: ItemKind :: Trait ( * is_auto, safety, ident , generics, bounds, items)
421
456
}
422
457
ItemKind :: TraitAlias ( generics, bounds) => {
458
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
459
+ let ident = self . lower_ident ( ident) ;
423
460
let ( generics, bounds) = self . lower_generics (
424
461
generics,
425
462
id,
@@ -431,9 +468,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
431
468
)
432
469
} ,
433
470
) ;
434
- hir:: ItemKind :: TraitAlias ( generics, bounds)
471
+ hir:: ItemKind :: TraitAlias ( ident , generics, bounds)
435
472
}
436
473
ItemKind :: MacroDef ( MacroDef { body, macro_rules } ) => {
474
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
475
+ let ident = self . lower_ident ( ident) ;
437
476
let body = P ( self . lower_delim_args ( body) ) ;
438
477
let def_id = self . local_def_id ( id) ;
439
478
let def_kind = self . tcx . def_kind ( def_id) ;
@@ -444,11 +483,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
444
483
) ;
445
484
} ;
446
485
let macro_def = self . arena . alloc ( ast:: MacroDef { body, macro_rules : * macro_rules } ) ;
447
- hir:: ItemKind :: Macro ( macro_def, macro_kind)
486
+ hir:: ItemKind :: Macro ( ident , macro_def, macro_kind)
448
487
}
449
488
ItemKind :: Delegation ( box delegation) => {
489
+ debug_assert_ne ! ( ident. name, kw:: Empty ) ;
490
+ let ident = self . lower_ident ( ident) ;
450
491
let delegation_results = self . lower_delegation ( delegation, id) ;
451
492
hir:: ItemKind :: Fn {
493
+ ident,
452
494
sig : delegation_results. sig ,
453
495
generics : delegation_results. generics ,
454
496
body : delegation_results. body_id ,
@@ -479,15 +521,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
479
521
prefix : & Path ,
480
522
id : NodeId ,
481
523
vis_span : Span ,
482
- ident : & mut Ident ,
483
524
attrs : & ' hir [ hir:: Attribute ] ,
484
525
) -> hir:: ItemKind < ' hir > {
485
526
let path = & tree. prefix ;
486
527
let segments = prefix. segments . iter ( ) . chain ( path. segments . iter ( ) ) . cloned ( ) . collect ( ) ;
487
528
488
529
match tree. kind {
489
530
UseTreeKind :: Simple ( rename) => {
490
- * ident = tree. ident ( ) ;
531
+ let mut ident = tree. ident ( ) ;
491
532
492
533
// First, apply the prefix to the path.
493
534
let mut path = Path { segments, span : path. span , tokens : None } ;
@@ -498,13 +539,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
498
539
{
499
540
let _ = path. segments . pop ( ) ;
500
541
if rename. is_none ( ) {
501
- * ident = path. segments . last ( ) . unwrap ( ) . ident ;
542
+ ident = path. segments . last ( ) . unwrap ( ) . ident ;
502
543
}
503
544
}
504
545
505
546
let res = self . lower_import_res ( id, path. span ) ;
506
547
let path = self . lower_use_path ( res, & path, ParamMode :: Explicit ) ;
507
- hir:: ItemKind :: Use ( path, hir:: UseKind :: Single )
548
+ let ident = self . lower_ident ( ident) ;
549
+ hir:: ItemKind :: Use ( path, hir:: UseKind :: Single ( ident) )
508
550
}
509
551
UseTreeKind :: Glob => {
510
552
let res = self . expect_full_res ( id) ;
@@ -551,20 +593,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
551
593
// own its own names, we have to adjust the owner before
552
594
// lowering the rest of the import.
553
595
self . with_hir_id_owner ( id, |this| {
554
- let mut ident = * ident;
555
-
556
596
// `prefix` is lowered multiple times, but in different HIR owners.
557
597
// So each segment gets renewed `HirId` with the same
558
598
// `ItemLocalId` and the new owner. (See `lower_node_id`)
559
- let kind =
560
- this. lower_use_tree ( use_tree, & prefix, id, vis_span, & mut ident, attrs) ;
599
+ let kind = this. lower_use_tree ( use_tree, & prefix, id, vis_span, attrs) ;
561
600
if !attrs. is_empty ( ) {
562
601
this. attrs . insert ( hir:: ItemLocalId :: ZERO , attrs) ;
563
602
}
564
603
565
604
let item = hir:: Item {
566
605
owner_id : hir:: OwnerId { def_id : new_hir_id } ,
567
- ident : this. lower_ident ( ident) ,
568
606
kind,
569
607
vis_span,
570
608
span : this. lower_span ( use_tree. span ) ,
@@ -604,7 +642,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
604
642
hir:: ItemKind :: Impl ( impl_) => {
605
643
self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
606
644
}
607
- hir:: ItemKind :: Trait ( _ , _ , _ , _ , _ ) => { }
645
+ hir:: ItemKind :: Trait ( .. ) => { }
608
646
kind => {
609
647
span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
610
648
}
@@ -760,6 +798,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
760
798
}
761
799
762
800
fn lower_trait_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: TraitItem < ' hir > {
801
+ debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
763
802
let hir_id = hir:: HirId :: make_owner ( self . current_hir_id_owner . def_id ) ;
764
803
let attrs = self . lower_attrs ( hir_id, & i. attrs , i. span ) ;
765
804
let trait_item_def_id = hir_id. expect_owner ( ) ;
@@ -907,6 +946,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
907
946
}
908
947
909
948
fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
949
+ debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
910
950
// Since `default impl` is not yet implemented, this is always true in impls.
911
951
let has_value = true ;
912
952
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
0 commit comments