@@ -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 ;
@@ -781,13 +784,12 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
781
784
id. def_id,
782
785
tcx. def_path_str( id. def_id. to_def_id( ) )
783
786
) ;
784
- let item_span = tcx. def_span ( id. def_id ) ;
785
787
let _indenter = indenter ( ) ;
786
788
match tcx. def_kind ( id. def_id ) {
787
789
DefKind :: Static ( ..) => {
788
790
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 ) ;
791
793
}
792
794
DefKind :: Const => {
793
795
tcx. ensure ( ) . typeck ( id. def_id ) ;
@@ -797,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
797
799
let hir:: ItemKind :: Enum ( ref enum_definition, _) = item. kind else {
798
800
return ;
799
801
} ;
800
- check_enum ( tcx, item_span , & enum_definition. variants , item. def_id ) ;
802
+ check_enum ( tcx, & enum_definition. variants , item. def_id ) ;
801
803
}
802
804
DefKind :: Fn => { } // entirely within check_item_body
803
805
DefKind :: Impl => {
@@ -848,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
848
850
}
849
851
}
850
852
DefKind :: Struct => {
851
- check_struct ( tcx, id. def_id , item_span ) ;
853
+ check_struct ( tcx, id. def_id ) ;
852
854
}
853
855
DefKind :: Union => {
854
- check_union ( tcx, id. def_id , item_span ) ;
856
+ check_union ( tcx, id. def_id ) ;
855
857
}
856
858
DefKind :: OpaqueTy => {
857
859
let item = tcx. hir ( ) . item ( id) ;
@@ -864,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
864
866
// See https://github.com/rust-lang/rust/issues/75100
865
867
if !tcx. sess . opts . actually_rustdoc {
866
868
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) ;
868
870
}
869
871
}
870
872
DefKind :: TyAlias => {
@@ -928,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
928
930
require_c_abi_if_c_variadic ( tcx, fn_decl, abi, item. span ) ;
929
931
}
930
932
hir:: ForeignItemKind :: Static ( ..) => {
931
- check_static_inhabited ( tcx, def_id, item . span ) ;
933
+ check_static_inhabited ( tcx, def_id) ;
932
934
}
933
935
_ => { }
934
936
}
@@ -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