@@ -198,8 +198,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
198
198
199
199
/// Checks that an opaque type does not contain cycles and does not use `Self` or `T::Foo`
200
200
/// projections that would result in "inheriting lifetimes".
201
- fn check_opaque ( tcx : TyCtxt < ' _ > , id : hir :: ItemId ) {
202
- let item = tcx. hir ( ) . item ( id ) ;
201
+ fn check_opaque ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
202
+ let item = tcx. hir ( ) . expect_item ( def_id ) ;
203
203
let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) = item. kind else {
204
204
tcx. dcx ( ) . span_delayed_bug ( item. span , "expected opaque item" ) ;
205
205
return ;
@@ -440,40 +440,35 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
440
440
}
441
441
}
442
442
443
- fn check_item_type ( tcx : TyCtxt < ' _ > , id : hir:: ItemId ) {
444
- debug ! (
445
- "check_item_type(it.def_id={:?}, it.name={})" ,
446
- id. owner_id,
447
- tcx. def_path_str( id. owner_id)
448
- ) ;
443
+ fn check_item_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
449
444
let _indenter = indenter ( ) ;
450
- match tcx. def_kind ( id . owner_id ) {
445
+ match tcx. def_kind ( def_id ) {
451
446
DefKind :: Static ( ..) => {
452
- tcx. ensure ( ) . typeck ( id . owner_id . def_id ) ;
453
- maybe_check_static_with_link_section ( tcx, id . owner_id . def_id ) ;
454
- check_static_inhabited ( tcx, id . owner_id . def_id ) ;
455
- check_static_linkage ( tcx, id . owner_id . def_id ) ;
447
+ tcx. ensure ( ) . typeck ( def_id) ;
448
+ maybe_check_static_with_link_section ( tcx, def_id) ;
449
+ check_static_inhabited ( tcx, def_id) ;
450
+ check_static_linkage ( tcx, def_id) ;
456
451
}
457
452
DefKind :: Const => {
458
- tcx. ensure ( ) . typeck ( id . owner_id . def_id ) ;
453
+ tcx. ensure ( ) . typeck ( def_id) ;
459
454
}
460
455
DefKind :: Enum => {
461
- check_enum ( tcx, id . owner_id . def_id ) ;
456
+ check_enum ( tcx, def_id) ;
462
457
}
463
458
DefKind :: Fn => { } // entirely within check_item_body
464
459
DefKind :: Impl { of_trait } => {
465
- if of_trait && let Some ( impl_trait_ref) = tcx. impl_trait_ref ( id . owner_id ) {
460
+ if of_trait && let Some ( impl_trait_ref) = tcx. impl_trait_ref ( def_id ) {
466
461
check_impl_items_against_trait (
467
462
tcx,
468
- id . owner_id . def_id ,
463
+ def_id,
469
464
impl_trait_ref. instantiate_identity ( ) ,
470
465
) ;
471
- check_on_unimplemented ( tcx, id ) ;
466
+ check_on_unimplemented ( tcx, def_id ) ;
472
467
}
473
468
}
474
469
DefKind :: Trait => {
475
- let assoc_items = tcx. associated_items ( id . owner_id ) ;
476
- check_on_unimplemented ( tcx, id ) ;
470
+ let assoc_items = tcx. associated_items ( def_id ) ;
471
+ check_on_unimplemented ( tcx, def_id ) ;
477
472
478
473
for & assoc_item in assoc_items. in_definition_order ( ) {
479
474
match assoc_item. kind {
@@ -482,43 +477,43 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
482
477
forbid_intrinsic_abi ( tcx, assoc_item. ident ( tcx) . span , abi) ;
483
478
}
484
479
ty:: AssocKind :: Type if assoc_item. defaultness ( tcx) . has_value ( ) => {
485
- let trait_args = GenericArgs :: identity_for_item ( tcx, id . owner_id ) ;
480
+ let trait_args = GenericArgs :: identity_for_item ( tcx, def_id ) ;
486
481
let _: Result < _ , rustc_errors:: ErrorGuaranteed > = check_type_bounds (
487
482
tcx,
488
483
assoc_item,
489
484
assoc_item,
490
- ty:: TraitRef :: new ( tcx, id . owner_id . to_def_id ( ) , trait_args) ,
485
+ ty:: TraitRef :: new ( tcx, def_id . to_def_id ( ) , trait_args) ,
491
486
) ;
492
487
}
493
488
_ => { }
494
489
}
495
490
}
496
491
}
497
492
DefKind :: Struct => {
498
- check_struct ( tcx, id . owner_id . def_id ) ;
493
+ check_struct ( tcx, def_id) ;
499
494
}
500
495
DefKind :: Union => {
501
- check_union ( tcx, id . owner_id . def_id ) ;
496
+ check_union ( tcx, def_id) ;
502
497
}
503
498
DefKind :: OpaqueTy => {
504
- let origin = tcx. opaque_type_origin ( id . owner_id . def_id ) ;
499
+ let origin = tcx. opaque_type_origin ( def_id) ;
505
500
if let hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id)
506
501
| hir:: OpaqueTyOrigin :: AsyncFn ( fn_def_id) = origin
507
502
&& let hir:: Node :: TraitItem ( trait_item) = tcx. hir_node_by_def_id ( fn_def_id)
508
503
&& let ( _, hir:: TraitFn :: Required ( ..) ) = trait_item. expect_fn ( )
509
504
{
510
505
// Skip opaques from RPIT in traits with no default body.
511
506
} else {
512
- check_opaque ( tcx, id ) ;
507
+ check_opaque ( tcx, def_id ) ;
513
508
}
514
509
}
515
510
DefKind :: TyAlias => {
516
- let pty_ty = tcx. type_of ( id . owner_id ) . instantiate_identity ( ) ;
517
- let generics = tcx. generics_of ( id . owner_id ) ;
511
+ let pty_ty = tcx. type_of ( def_id ) . instantiate_identity ( ) ;
512
+ let generics = tcx. generics_of ( def_id ) ;
518
513
check_type_params_are_used ( tcx, generics, pty_ty) ;
519
514
}
520
515
DefKind :: ForeignMod => {
521
- let it = tcx. hir ( ) . item ( id ) ;
516
+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
522
517
let hir:: ItemKind :: ForeignMod { abi, items } = it. kind else {
523
518
return ;
524
519
} ;
@@ -589,19 +584,19 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
589
584
}
590
585
}
591
586
DefKind :: GlobalAsm => {
592
- let it = tcx. hir ( ) . item ( id ) ;
587
+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
593
588
let hir:: ItemKind :: GlobalAsm ( asm) = it. kind else {
594
589
span_bug ! ( it. span, "DefKind::GlobalAsm but got {:#?}" , it)
595
590
} ;
596
- InlineAsmCtxt :: new_global_asm ( tcx) . check_asm ( asm, id . owner_id . def_id ) ;
591
+ InlineAsmCtxt :: new_global_asm ( tcx) . check_asm ( asm, def_id) ;
597
592
}
598
593
_ => { }
599
594
}
600
595
}
601
596
602
- pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , item : hir :: ItemId ) {
597
+ pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
603
598
// an error would be reported if this fails.
604
- let _ = OnUnimplementedDirective :: of_item ( tcx, item . owner_id . to_def_id ( ) ) ;
599
+ let _ = OnUnimplementedDirective :: of_item ( tcx, def_id . to_def_id ( ) ) ;
605
600
}
606
601
607
602
pub ( super ) fn check_specialization_validity < ' tcx > (
@@ -1312,7 +1307,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
1312
1307
pub ( super ) fn check_mod_item_types ( tcx : TyCtxt < ' _ > , module_def_id : LocalModDefId ) {
1313
1308
let module = tcx. hir_module_items ( module_def_id) ;
1314
1309
for id in module. items ( ) {
1315
- check_item_type ( tcx, id) ;
1310
+ check_item_type ( tcx, id. owner_id . def_id ) ;
1316
1311
}
1317
1312
if module_def_id == LocalModDefId :: CRATE_DEF_ID {
1318
1313
super :: entry:: check_for_entry_fn ( tcx) ;
0 commit comments