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