@@ -375,8 +375,9 @@ fn check_alloc_error_fn(
375375 }
376376}
377377
378- fn check_struct ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , span : Span ) {
378+ fn check_struct ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
379379 let def = tcx. adt_def ( def_id) ;
380+ let span = tcx. def_span ( def_id) ;
380381 def. destructor ( tcx) ; // force the destructor to be evaluated
381382 check_representable ( tcx, span, def_id) ;
382383
@@ -388,8 +389,9 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
388389 check_packed ( tcx, span, def) ;
389390}
390391
391- fn check_union ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , span : Span ) {
392+ fn check_union ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
392393 let def = tcx. adt_def ( def_id) ;
394+ let span = tcx. def_span ( def_id) ;
393395 def. destructor ( tcx) ; // force the destructor to be evaluated
394396 check_representable ( tcx, span, def_id) ;
395397 check_transparent ( tcx, span, def) ;
@@ -471,13 +473,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
471473}
472474
473475/// Check that a `static` is inhabited.
474- fn check_static_inhabited < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , span : Span ) {
476+ fn check_static_inhabited < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) {
475477 // Make sure statics are inhabited.
476478 // Other parts of the compiler assume that there are no uninhabited places. In principle it
477479 // would be enough to check this for `extern` statics, as statics with an initializer will
478480 // have UB during initialization if they are uninhabited, but there also seems to be no good
479481 // reason to allow any statics to be uninhabited.
480482 let ty = tcx. type_of ( def_id) ;
483+ let span = tcx. def_span ( def_id) ;
481484 let layout = match tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( ty) ) {
482485 Ok ( l) => l,
483486 // Foreign statics that overflow their allowed size should emit an error
@@ -524,9 +527,9 @@ pub(super) fn check_opaque<'tcx>(
524527 tcx : TyCtxt < ' tcx > ,
525528 def_id : LocalDefId ,
526529 substs : SubstsRef < ' tcx > ,
527- span : Span ,
528530 origin : & hir:: OpaqueTyOrigin ,
529531) {
532+ let span = tcx. def_span ( def_id) ;
530533 check_opaque_for_inheriting_lifetimes ( tcx, def_id, span) ;
531534 if tcx. type_of ( def_id) . references_error ( ) {
532535 return ;
@@ -781,13 +784,12 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
781784 id. def_id,
782785 tcx. def_path_str( id. def_id. to_def_id( ) )
783786 ) ;
784- let item_span = tcx. def_span ( id. def_id ) ;
785787 let _indenter = indenter ( ) ;
786788 match tcx. def_kind ( id. def_id ) {
787789 DefKind :: Static ( ..) => {
788790 tcx. ensure ( ) . typeck ( id. def_id ) ;
789- maybe_check_static_with_link_section ( tcx, id. def_id , item_span ) ;
790- check_static_inhabited ( tcx, id. def_id , item_span ) ;
791+ maybe_check_static_with_link_section ( tcx, id. def_id ) ;
792+ check_static_inhabited ( tcx, id. def_id ) ;
791793 }
792794 DefKind :: Const => {
793795 tcx. ensure ( ) . typeck ( id. def_id ) ;
@@ -797,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
797799 let hir:: ItemKind :: Enum ( ref enum_definition, _) = item. kind else {
798800 return ;
799801 } ;
800- check_enum ( tcx, item_span , & enum_definition. variants , item. def_id ) ;
802+ check_enum ( tcx, & enum_definition. variants , item. def_id ) ;
801803 }
802804 DefKind :: Fn => { } // entirely within check_item_body
803805 DefKind :: Impl => {
@@ -848,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
848850 }
849851 }
850852 DefKind :: Struct => {
851- check_struct ( tcx, id. def_id , item_span ) ;
853+ check_struct ( tcx, id. def_id ) ;
852854 }
853855 DefKind :: Union => {
854- check_union ( tcx, id. def_id , item_span ) ;
856+ check_union ( tcx, id. def_id ) ;
855857 }
856858 DefKind :: OpaqueTy => {
857859 let item = tcx. hir ( ) . item ( id) ;
@@ -864,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
864866 // See https://github.com/rust-lang/rust/issues/75100
865867 if !tcx. sess . opts . actually_rustdoc {
866868 let substs = InternalSubsts :: identity_for_item ( tcx, item. def_id . to_def_id ( ) ) ;
867- check_opaque ( tcx, item. def_id , substs, item_span , & origin) ;
869+ check_opaque ( tcx, item. def_id , substs, & origin) ;
868870 }
869871 }
870872 DefKind :: TyAlias => {
@@ -928,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
928930 require_c_abi_if_c_variadic ( tcx, fn_decl, abi, item. span ) ;
929931 }
930932 hir:: ForeignItemKind :: Static ( ..) => {
931- check_static_inhabited ( tcx, def_id, item . span ) ;
933+ check_static_inhabited ( tcx, def_id) ;
932934 }
933935 _ => { }
934936 }
@@ -1442,13 +1444,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
14421444}
14431445
14441446#[ allow( trivial_numeric_casts) ]
1445- fn check_enum < ' tcx > (
1446- tcx : TyCtxt < ' tcx > ,
1447- sp : Span ,
1448- vs : & ' tcx [ hir:: Variant < ' tcx > ] ,
1449- def_id : LocalDefId ,
1450- ) {
1447+ fn check_enum < ' tcx > ( tcx : TyCtxt < ' tcx > , vs : & ' tcx [ hir:: Variant < ' tcx > ] , def_id : LocalDefId ) {
14511448 let def = tcx. adt_def ( def_id) ;
1449+ let sp = tcx. def_span ( def_id) ;
14521450 def. destructor ( tcx) ; // force the destructor to be evaluated
14531451
14541452 if vs. is_empty ( ) {
0 commit comments