@@ -185,17 +185,17 @@ where
185
185
}
186
186
187
187
fn check_well_formed ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Result < ( ) , ErrorGuaranteed > {
188
- crate :: check:: check:: check_item_type ( tcx, def_id) ;
188
+ let mut res = crate :: check:: check:: check_item_type ( tcx, def_id) ;
189
189
let node = tcx. hir_node_by_def_id ( def_id) ;
190
- let mut res = match node {
190
+ res = res . and ( match node {
191
191
hir:: Node :: Crate ( _) => bug ! ( "check_well_formed cannot be applied to the crate root" ) ,
192
192
hir:: Node :: Item ( item) => check_item ( tcx, item) ,
193
193
hir:: Node :: TraitItem ( item) => check_trait_item ( tcx, item) ,
194
194
hir:: Node :: ImplItem ( item) => check_impl_item ( tcx, item) ,
195
195
hir:: Node :: ForeignItem ( item) => check_foreign_item ( tcx, item) ,
196
196
hir:: Node :: ConstBlock ( _) | hir:: Node :: Expr ( _) | hir:: Node :: OpaqueTy ( _) => Ok ( ( ) ) ,
197
197
_ => unreachable ! ( "{node:?}" ) ,
198
- } ;
198
+ } ) ;
199
199
200
200
for param in & tcx. generics_of ( def_id) . own_params {
201
201
res = res. and ( check_param_wf ( tcx, param) ) ;
@@ -291,9 +291,6 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
291
291
res
292
292
}
293
293
hir:: ItemKind :: Fn { ident, sig, .. } => check_item_fn ( tcx, def_id, ident, sig. decl ) ,
294
- hir:: ItemKind :: Static ( _, _, ty, _) => {
295
- check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
296
- }
297
294
hir:: ItemKind :: Const ( _, _, ty, _) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
298
295
hir:: ItemKind :: Struct ( _, generics, _) => {
299
296
let res = check_type_defn ( tcx, item, false ) ;
@@ -347,10 +344,7 @@ fn check_foreign_item<'tcx>(
347
344
348
345
match item. kind {
349
346
hir:: ForeignItemKind :: Fn ( sig, ..) => check_item_fn ( tcx, def_id, item. ident , sig. decl ) ,
350
- hir:: ForeignItemKind :: Static ( ty, ..) => {
351
- check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
352
- }
353
- hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
347
+ hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
354
348
}
355
349
}
356
350
@@ -1251,61 +1245,54 @@ fn check_item_fn(
1251
1245
} )
1252
1246
}
1253
1247
1254
- enum UnsizedHandling {
1255
- Forbid ,
1256
- AllowIfForeignTail ,
1257
- }
1258
-
1259
- #[ instrument( level = "debug" , skip( tcx, ty_span, unsized_handling) ) ]
1260
- fn check_static_item (
1248
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1249
+ pub ( super ) fn check_static_item (
1261
1250
tcx : TyCtxt < ' _ > ,
1262
1251
item_id : LocalDefId ,
1263
- ty_span : Span ,
1264
- unsized_handling : UnsizedHandling ,
1265
1252
) -> Result < ( ) , ErrorGuaranteed > {
1266
1253
enter_wf_checking_ctxt ( tcx, item_id, |wfcx| {
1267
1254
let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
1268
- let item_ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1269
-
1270
- let forbid_unsized = match unsized_handling {
1271
- UnsizedHandling :: Forbid => true ,
1272
- UnsizedHandling :: AllowIfForeignTail => {
1273
- let tail =
1274
- tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1275
- !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1276
- }
1255
+ let item_ty = wfcx. deeply_normalize ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1256
+
1257
+ let is_foreign_item = tcx. is_foreign_item ( item_id) ;
1258
+
1259
+ let forbid_unsized = !is_foreign_item || {
1260
+ let tail = tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1261
+ !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1277
1262
} ;
1278
1263
1279
- wfcx. register_wf_obligation ( ty_span , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1264
+ wfcx. register_wf_obligation ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1280
1265
if forbid_unsized {
1266
+ let span = tcx. def_span ( item_id) ;
1281
1267
wfcx. register_bound (
1282
1268
traits:: ObligationCause :: new (
1283
- ty_span ,
1269
+ span ,
1284
1270
wfcx. body_def_id ,
1285
1271
ObligationCauseCode :: SizedConstOrStatic ,
1286
1272
) ,
1287
1273
wfcx. param_env ,
1288
1274
item_ty,
1289
- tcx. require_lang_item ( LangItem :: Sized , ty_span ) ,
1275
+ tcx. require_lang_item ( LangItem :: Sized , span ) ,
1290
1276
) ;
1291
1277
}
1292
1278
1293
1279
// Ensure that the end result is `Sync` in a non-thread local `static`.
1294
1280
let should_check_for_sync = tcx. static_mutability ( item_id. to_def_id ( ) )
1295
1281
== Some ( hir:: Mutability :: Not )
1296
- && !tcx . is_foreign_item ( item_id . to_def_id ( ) )
1282
+ && !is_foreign_item
1297
1283
&& !tcx. is_thread_local_static ( item_id. to_def_id ( ) ) ;
1298
1284
1299
1285
if should_check_for_sync {
1286
+ let span = tcx. def_span ( item_id) ;
1300
1287
wfcx. register_bound (
1301
1288
traits:: ObligationCause :: new (
1302
- ty_span ,
1289
+ span ,
1303
1290
wfcx. body_def_id ,
1304
1291
ObligationCauseCode :: SharedStatic ,
1305
1292
) ,
1306
1293
wfcx. param_env ,
1307
1294
item_ty,
1308
- tcx. require_lang_item ( LangItem :: Sync , ty_span ) ,
1295
+ tcx. require_lang_item ( LangItem :: Sync , span ) ,
1309
1296
) ;
1310
1297
}
1311
1298
Ok ( ( ) )
0 commit comments