@@ -8,7 +8,7 @@ use rustc_attr as attr;
8
8
use rustc_errors:: { ErrorGuaranteed , MultiSpan } ;
9
9
use rustc_hir as hir;
10
10
use rustc_hir:: def:: { CtorKind , DefKind } ;
11
- use rustc_hir:: def_id:: LocalModDefId ;
11
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
12
12
use rustc_hir:: Node ;
13
13
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
14
14
use rustc_infer:: traits:: { Obligation , TraitEngineExt as _} ;
@@ -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,31 @@ 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
+ pub ( crate ) 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 ) {
466
- check_impl_items_against_trait (
467
- tcx,
468
- id. owner_id . def_id ,
469
- impl_trait_ref. instantiate_identity ( ) ,
470
- ) ;
471
- check_on_unimplemented ( tcx, id) ;
460
+ if of_trait && let Some ( impl_trait_ref) = tcx. impl_trait_ref ( def_id) {
461
+ check_impl_items_against_trait ( tcx, def_id, impl_trait_ref. instantiate_identity ( ) ) ;
462
+ check_on_unimplemented ( tcx, def_id) ;
472
463
}
473
464
}
474
465
DefKind :: Trait => {
475
- let assoc_items = tcx. associated_items ( id . owner_id ) ;
476
- check_on_unimplemented ( tcx, id ) ;
466
+ let assoc_items = tcx. associated_items ( def_id ) ;
467
+ check_on_unimplemented ( tcx, def_id ) ;
477
468
478
469
for & assoc_item in assoc_items. in_definition_order ( ) {
479
470
match assoc_item. kind {
@@ -482,43 +473,43 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
482
473
forbid_intrinsic_abi ( tcx, assoc_item. ident ( tcx) . span , abi) ;
483
474
}
484
475
ty:: AssocKind :: Type if assoc_item. defaultness ( tcx) . has_value ( ) => {
485
- let trait_args = GenericArgs :: identity_for_item ( tcx, id . owner_id ) ;
476
+ let trait_args = GenericArgs :: identity_for_item ( tcx, def_id ) ;
486
477
let _: Result < _ , rustc_errors:: ErrorGuaranteed > = check_type_bounds (
487
478
tcx,
488
479
assoc_item,
489
480
assoc_item,
490
- ty:: TraitRef :: new ( tcx, id . owner_id . to_def_id ( ) , trait_args) ,
481
+ ty:: TraitRef :: new ( tcx, def_id . to_def_id ( ) , trait_args) ,
491
482
) ;
492
483
}
493
484
_ => { }
494
485
}
495
486
}
496
487
}
497
488
DefKind :: Struct => {
498
- check_struct ( tcx, id . owner_id . def_id ) ;
489
+ check_struct ( tcx, def_id) ;
499
490
}
500
491
DefKind :: Union => {
501
- check_union ( tcx, id . owner_id . def_id ) ;
492
+ check_union ( tcx, def_id) ;
502
493
}
503
494
DefKind :: OpaqueTy => {
504
- let origin = tcx. opaque_type_origin ( id . owner_id . def_id ) ;
495
+ let origin = tcx. opaque_type_origin ( def_id) ;
505
496
if let hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id)
506
497
| hir:: OpaqueTyOrigin :: AsyncFn ( fn_def_id) = origin
507
498
&& let hir:: Node :: TraitItem ( trait_item) = tcx. hir_node_by_def_id ( fn_def_id)
508
499
&& let ( _, hir:: TraitFn :: Required ( ..) ) = trait_item. expect_fn ( )
509
500
{
510
501
// Skip opaques from RPIT in traits with no default body.
511
502
} else {
512
- check_opaque ( tcx, id ) ;
503
+ check_opaque ( tcx, def_id ) ;
513
504
}
514
505
}
515
506
DefKind :: TyAlias => {
516
- let pty_ty = tcx. type_of ( id . owner_id ) . instantiate_identity ( ) ;
517
- let generics = tcx. generics_of ( id . owner_id ) ;
507
+ let pty_ty = tcx. type_of ( def_id ) . instantiate_identity ( ) ;
508
+ let generics = tcx. generics_of ( def_id ) ;
518
509
check_type_params_are_used ( tcx, generics, pty_ty) ;
519
510
}
520
511
DefKind :: ForeignMod => {
521
- let it = tcx. hir ( ) . item ( id ) ;
512
+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
522
513
let hir:: ItemKind :: ForeignMod { abi, items } = it. kind else {
523
514
return ;
524
515
} ;
@@ -589,19 +580,19 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
589
580
}
590
581
}
591
582
DefKind :: GlobalAsm => {
592
- let it = tcx. hir ( ) . item ( id ) ;
583
+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
593
584
let hir:: ItemKind :: GlobalAsm ( asm) = it. kind else {
594
585
span_bug ! ( it. span, "DefKind::GlobalAsm but got {:#?}" , it)
595
586
} ;
596
- InlineAsmCtxt :: new_global_asm ( tcx) . check_asm ( asm, id . owner_id . def_id ) ;
587
+ InlineAsmCtxt :: new_global_asm ( tcx) . check_asm ( asm, def_id) ;
597
588
}
598
589
_ => { }
599
590
}
600
591
}
601
592
602
- pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , item : hir :: ItemId ) {
593
+ pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
603
594
// an error would be reported if this fails.
604
- let _ = OnUnimplementedDirective :: of_item ( tcx, item . owner_id . to_def_id ( ) ) ;
595
+ let _ = OnUnimplementedDirective :: of_item ( tcx, def_id . to_def_id ( ) ) ;
605
596
}
606
597
607
598
pub ( super ) fn check_specialization_validity < ' tcx > (
@@ -1309,16 +1300,6 @@ pub(super) fn check_type_params_are_used<'tcx>(
1309
1300
}
1310
1301
}
1311
1302
1312
- pub ( super ) fn check_mod_item_types ( tcx : TyCtxt < ' _ > , module_def_id : LocalModDefId ) {
1313
- let module = tcx. hir_module_items ( module_def_id) ;
1314
- for id in module. items ( ) {
1315
- check_item_type ( tcx, id) ;
1316
- }
1317
- if module_def_id == LocalModDefId :: CRATE_DEF_ID {
1318
- super :: entry:: check_for_entry_fn ( tcx) ;
1319
- }
1320
- }
1321
-
1322
1303
fn async_opaque_type_cycle_error ( tcx : TyCtxt < ' _ > , span : Span ) -> ErrorGuaranteed {
1323
1304
struct_span_err ! ( tcx. dcx( ) , span, E0733 , "recursion in an `async fn` requires boxing" )
1324
1305
. span_label ( span, "recursive `async fn`" )
0 commit comments