@@ -375,8 +375,9 @@ fn check_alloc_error_fn(
375
375
}
376
376
}
377
377
378
- fn check_struct ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , span : Span ) {
378
+ fn check_struct ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
379
379
let def = tcx. adt_def ( def_id) ;
380
+ let span = tcx. def_span ( def_id) ;
380
381
def. destructor ( tcx) ; // force the destructor to be evaluated
381
382
check_representable ( tcx, span, def_id) ;
382
383
@@ -388,8 +389,9 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
388
389
check_packed ( tcx, span, def) ;
389
390
}
390
391
391
- fn check_union ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , span : Span ) {
392
+ fn check_union ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
392
393
let def = tcx. adt_def ( def_id) ;
394
+ let span = tcx. def_span ( def_id) ;
393
395
def. destructor ( tcx) ; // force the destructor to be evaluated
394
396
check_representable ( tcx, span, def_id) ;
395
397
check_transparent ( tcx, span, def) ;
@@ -471,13 +473,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
471
473
}
472
474
473
475
/// 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 ) {
475
477
// Make sure statics are inhabited.
476
478
// Other parts of the compiler assume that there are no uninhabited places. In principle it
477
479
// would be enough to check this for `extern` statics, as statics with an initializer will
478
480
// have UB during initialization if they are uninhabited, but there also seems to be no good
479
481
// reason to allow any statics to be uninhabited.
480
482
let ty = tcx. type_of ( def_id) ;
483
+ let span = tcx. def_span ( def_id) ;
481
484
let layout = match tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( ty) ) {
482
485
Ok ( l) => l,
483
486
// Foreign statics that overflow their allowed size should emit an error
@@ -524,9 +527,9 @@ pub(super) fn check_opaque<'tcx>(
524
527
tcx : TyCtxt < ' tcx > ,
525
528
def_id : LocalDefId ,
526
529
substs : SubstsRef < ' tcx > ,
527
- span : Span ,
528
530
origin : & hir:: OpaqueTyOrigin ,
529
531
) {
532
+ let span = tcx. def_span ( def_id) ;
530
533
check_opaque_for_inheriting_lifetimes ( tcx, def_id, span) ;
531
534
if tcx. type_of ( def_id) . references_error ( ) {
532
535
return ;
@@ -785,8 +788,8 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
785
788
match tcx. def_kind ( id. def_id ) {
786
789
DefKind :: Static ( ..) => {
787
790
tcx. ensure ( ) . typeck ( id. def_id ) ;
788
- maybe_check_static_with_link_section ( tcx, id. def_id , tcx . def_span ( id . def_id ) ) ;
789
- check_static_inhabited ( tcx, id. def_id , tcx . def_span ( id . def_id ) ) ;
791
+ maybe_check_static_with_link_section ( tcx, id. def_id ) ;
792
+ check_static_inhabited ( tcx, id. def_id ) ;
790
793
}
791
794
DefKind :: Const => {
792
795
tcx. ensure ( ) . typeck ( id. def_id ) ;
@@ -796,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
796
799
let hir:: ItemKind :: Enum ( ref enum_definition, _) = item. kind else {
797
800
return ;
798
801
} ;
799
- check_enum ( tcx, item . span , & enum_definition. variants , item. def_id ) ;
802
+ check_enum ( tcx, & enum_definition. variants , item. def_id ) ;
800
803
}
801
804
DefKind :: Fn => { } // entirely within check_item_body
802
805
DefKind :: Impl => {
@@ -847,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
847
850
}
848
851
}
849
852
DefKind :: Struct => {
850
- check_struct ( tcx, id. def_id , tcx . def_span ( id . def_id ) ) ;
853
+ check_struct ( tcx, id. def_id ) ;
851
854
}
852
855
DefKind :: Union => {
853
- check_union ( tcx, id. def_id , tcx . def_span ( id . def_id ) ) ;
856
+ check_union ( tcx, id. def_id ) ;
854
857
}
855
858
DefKind :: OpaqueTy => {
856
859
let item = tcx. hir ( ) . item ( id) ;
@@ -863,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
863
866
// See https://github.com/rust-lang/rust/issues/75100
864
867
if !tcx. sess . opts . actually_rustdoc {
865
868
let substs = InternalSubsts :: identity_for_item ( tcx, item. def_id . to_def_id ( ) ) ;
866
- check_opaque ( tcx, item. def_id , substs, item . span , & origin) ;
869
+ check_opaque ( tcx, item. def_id , substs, & origin) ;
867
870
}
868
871
}
869
872
DefKind :: TyAlias => {
@@ -927,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
927
930
require_c_abi_if_c_variadic ( tcx, fn_decl, abi, item. span ) ;
928
931
}
929
932
hir:: ForeignItemKind :: Static ( ..) => {
930
- check_static_inhabited ( tcx, def_id, item . span ) ;
933
+ check_static_inhabited ( tcx, def_id) ;
931
934
}
932
935
_ => { }
933
936
}
@@ -1328,7 +1331,6 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
1328
1331
if !adt. repr ( ) . transparent ( ) {
1329
1332
return ;
1330
1333
}
1331
- let sp = tcx. sess . source_map ( ) . guess_head_span ( sp) ;
1332
1334
1333
1335
if adt. is_union ( ) && !tcx. features ( ) . transparent_unions {
1334
1336
feature_err (
@@ -1442,13 +1444,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
1442
1444
}
1443
1445
1444
1446
#[ 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 ) {
1451
1448
let def = tcx. adt_def ( def_id) ;
1449
+ let sp = tcx. def_span ( def_id) ;
1452
1450
def. destructor ( tcx) ; // force the destructor to be evaluated
1453
1451
1454
1452
if vs. is_empty ( ) {
0 commit comments