@@ -186,17 +186,17 @@ where
186
186
}
187
187
188
188
fn check_well_formed ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Result < ( ) , ErrorGuaranteed > {
189
- crate :: check:: check:: check_item_type ( tcx, def_id) ;
189
+ let mut res = crate :: check:: check:: check_item_type ( tcx, def_id) ;
190
190
let node = tcx. hir_node_by_def_id ( def_id) ;
191
- let mut res = match node {
191
+ res = res . and ( match node {
192
192
hir:: Node :: Crate ( _) => bug ! ( "check_well_formed cannot be applied to the crate root" ) ,
193
193
hir:: Node :: Item ( item) => check_item ( tcx, item) ,
194
194
hir:: Node :: TraitItem ( item) => check_trait_item ( tcx, item) ,
195
195
hir:: Node :: ImplItem ( item) => check_impl_item ( tcx, item) ,
196
196
hir:: Node :: ForeignItem ( item) => check_foreign_item ( tcx, item) ,
197
197
hir:: Node :: OpaqueTy ( _) => Ok ( ( ) ) ,
198
198
_ => unreachable ! ( "{node:?}" ) ,
199
- } ;
199
+ } ) ;
200
200
201
201
for param in & tcx. generics_of ( def_id) . own_params {
202
202
res = res. and ( check_param_wf ( tcx, param) ) ;
@@ -292,9 +292,6 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
292
292
res
293
293
}
294
294
hir:: ItemKind :: Fn { ident, sig, .. } => check_item_fn ( tcx, def_id, ident, sig. decl ) ,
295
- hir:: ItemKind :: Static ( _, _, ty, _) => {
296
- check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
297
- }
298
295
hir:: ItemKind :: Const ( _, _, ty, _) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
299
296
hir:: ItemKind :: Struct ( _, generics, _) => {
300
297
let res = check_type_defn ( tcx, item, false ) ;
@@ -350,10 +347,7 @@ fn check_foreign_item<'tcx>(
350
347
351
348
match item. kind {
352
349
hir:: ForeignItemKind :: Fn ( sig, ..) => check_item_fn ( tcx, def_id, item. ident , sig. decl ) ,
353
- hir:: ForeignItemKind :: Static ( ty, ..) => {
354
- check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
355
- }
356
- hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
350
+ hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
357
351
}
358
352
}
359
353
@@ -1315,61 +1309,52 @@ fn check_item_fn(
1315
1309
} )
1316
1310
}
1317
1311
1318
- enum UnsizedHandling {
1319
- Forbid ,
1320
- AllowIfForeignTail ,
1321
- }
1322
-
1323
- #[ instrument( level = "debug" , skip( tcx, ty_span, unsized_handling) ) ]
1324
- fn check_static_item (
1312
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1313
+ pub ( super ) fn check_static_item (
1325
1314
tcx : TyCtxt < ' _ > ,
1326
1315
item_id : LocalDefId ,
1327
- ty_span : Span ,
1328
- unsized_handling : UnsizedHandling ,
1329
1316
) -> Result < ( ) , ErrorGuaranteed > {
1330
1317
enter_wf_checking_ctxt ( tcx, item_id, |wfcx| {
1331
1318
let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
1332
- let item_ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1333
-
1334
- let forbid_unsized = match unsized_handling {
1335
- UnsizedHandling :: Forbid => true ,
1336
- UnsizedHandling :: AllowIfForeignTail => {
1337
- let tail =
1338
- tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1339
- !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1340
- }
1319
+ let item_ty = wfcx. deeply_normalize ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1320
+
1321
+ let is_foreign_item = tcx. is_foreign_item ( item_id) ;
1322
+
1323
+ let forbid_unsized = !is_foreign_item || {
1324
+ let tail = tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1325
+ !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1341
1326
} ;
1342
1327
1343
- wfcx. register_wf_obligation ( ty_span , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1328
+ wfcx. register_wf_obligation ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1344
1329
if forbid_unsized {
1345
1330
wfcx. register_bound (
1346
1331
traits:: ObligationCause :: new (
1347
- ty_span ,
1332
+ DUMMY_SP ,
1348
1333
wfcx. body_def_id ,
1349
1334
ObligationCauseCode :: SizedConstOrStatic ,
1350
1335
) ,
1351
1336
wfcx. param_env ,
1352
1337
item_ty,
1353
- tcx. require_lang_item ( LangItem :: Sized , Some ( ty_span ) ) ,
1338
+ tcx. require_lang_item ( LangItem :: Sized , Some ( tcx . def_span ( item_id ) ) ) ,
1354
1339
) ;
1355
1340
}
1356
1341
1357
1342
// Ensure that the end result is `Sync` in a non-thread local `static`.
1358
1343
let should_check_for_sync = tcx. static_mutability ( item_id. to_def_id ( ) )
1359
1344
== Some ( hir:: Mutability :: Not )
1360
- && !tcx . is_foreign_item ( item_id . to_def_id ( ) )
1345
+ && !is_foreign_item
1361
1346
&& !tcx. is_thread_local_static ( item_id. to_def_id ( ) ) ;
1362
1347
1363
1348
if should_check_for_sync {
1364
1349
wfcx. register_bound (
1365
1350
traits:: ObligationCause :: new (
1366
- ty_span ,
1351
+ DUMMY_SP ,
1367
1352
wfcx. body_def_id ,
1368
1353
ObligationCauseCode :: SharedStatic ,
1369
1354
) ,
1370
1355
wfcx. param_env ,
1371
1356
item_ty,
1372
- tcx. require_lang_item ( LangItem :: Sync , Some ( ty_span ) ) ,
1357
+ tcx. require_lang_item ( LangItem :: Sync , Some ( tcx . def_span ( item_id ) ) ) ,
1373
1358
) ;
1374
1359
}
1375
1360
Ok ( ( ) )
0 commit comments