@@ -8,7 +8,7 @@ use rustc_attr as attr;
88use rustc_errors:: { ErrorGuaranteed , MultiSpan } ;
99use rustc_hir as hir;
1010use rustc_hir:: def:: { CtorKind , DefKind } ;
11- use rustc_hir:: def_id:: LocalModDefId ;
11+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
1212use rustc_hir:: Node ;
1313use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
1414use rustc_infer:: traits:: { Obligation , TraitEngineExt as _} ;
@@ -198,8 +198,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
198198
199199/// Checks that an opaque type does not contain cycles and does not use `Self` or `T::Foo`
200200/// 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 ) ;
203203 let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) = item. kind else {
204204 tcx. dcx ( ) . span_delayed_bug ( item. span , "expected opaque item" ) ;
205205 return ;
@@ -440,40 +440,31 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
440440 }
441441}
442442
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 ) {
449444 let _indenter = indenter ( ) ;
450- match tcx. def_kind ( id . owner_id ) {
445+ match tcx. def_kind ( def_id ) {
451446 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) ;
456451 }
457452 DefKind :: Const => {
458- tcx. ensure ( ) . typeck ( id . owner_id . def_id ) ;
453+ tcx. ensure ( ) . typeck ( def_id) ;
459454 }
460455 DefKind :: Enum => {
461- check_enum ( tcx, id . owner_id . def_id ) ;
456+ check_enum ( tcx, def_id) ;
462457 }
463458 DefKind :: Fn => { } // entirely within check_item_body
464459 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) ;
472463 }
473464 }
474465 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 ) ;
477468
478469 for & assoc_item in assoc_items. in_definition_order ( ) {
479470 match assoc_item. kind {
@@ -482,43 +473,43 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
482473 forbid_intrinsic_abi ( tcx, assoc_item. ident ( tcx) . span , abi) ;
483474 }
484475 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 ) ;
486477 let _: Result < _ , rustc_errors:: ErrorGuaranteed > = check_type_bounds (
487478 tcx,
488479 assoc_item,
489480 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) ,
491482 ) ;
492483 }
493484 _ => { }
494485 }
495486 }
496487 }
497488 DefKind :: Struct => {
498- check_struct ( tcx, id . owner_id . def_id ) ;
489+ check_struct ( tcx, def_id) ;
499490 }
500491 DefKind :: Union => {
501- check_union ( tcx, id . owner_id . def_id ) ;
492+ check_union ( tcx, def_id) ;
502493 }
503494 DefKind :: OpaqueTy => {
504- let origin = tcx. opaque_type_origin ( id . owner_id . def_id ) ;
495+ let origin = tcx. opaque_type_origin ( def_id) ;
505496 if let hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id)
506497 | hir:: OpaqueTyOrigin :: AsyncFn ( fn_def_id) = origin
507498 && let hir:: Node :: TraitItem ( trait_item) = tcx. hir_node_by_def_id ( fn_def_id)
508499 && let ( _, hir:: TraitFn :: Required ( ..) ) = trait_item. expect_fn ( )
509500 {
510501 // Skip opaques from RPIT in traits with no default body.
511502 } else {
512- check_opaque ( tcx, id ) ;
503+ check_opaque ( tcx, def_id ) ;
513504 }
514505 }
515506 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 ) ;
518509 check_type_params_are_used ( tcx, generics, pty_ty) ;
519510 }
520511 DefKind :: ForeignMod => {
521- let it = tcx. hir ( ) . item ( id ) ;
512+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
522513 let hir:: ItemKind :: ForeignMod { abi, items } = it. kind else {
523514 return ;
524515 } ;
@@ -589,19 +580,19 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
589580 }
590581 }
591582 DefKind :: GlobalAsm => {
592- let it = tcx. hir ( ) . item ( id ) ;
583+ let it = tcx. hir ( ) . expect_item ( def_id ) ;
593584 let hir:: ItemKind :: GlobalAsm ( asm) = it. kind else {
594585 span_bug ! ( it. span, "DefKind::GlobalAsm but got {:#?}" , it)
595586 } ;
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) ;
597588 }
598589 _ => { }
599590 }
600591}
601592
602- pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , item : hir :: ItemId ) {
593+ pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
603594 // 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 ( ) ) ;
605596}
606597
607598pub ( super ) fn check_specialization_validity < ' tcx > (
@@ -1309,16 +1300,6 @@ pub(super) fn check_type_params_are_used<'tcx>(
13091300 }
13101301}
13111302
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-
13221303fn async_opaque_type_cycle_error ( tcx : TyCtxt < ' _ > , span : Span ) -> ErrorGuaranteed {
13231304 struct_span_err ! ( tcx. dcx( ) , span, E0733 , "recursion in an `async fn` requires boxing" )
13241305 . span_label ( span, "recursive `async fn`" )
0 commit comments