@@ -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
@@ -1247,61 +1241,52 @@ fn check_item_fn(
1247
1241
} )
1248
1242
}
1249
1243
1250
- enum UnsizedHandling {
1251
- Forbid ,
1252
- AllowIfForeignTail ,
1253
- }
1254
-
1255
- #[ instrument( level = "debug" , skip( tcx, ty_span, unsized_handling) ) ]
1256
- fn check_static_item (
1244
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1245
+ pub ( super ) fn check_static_item (
1257
1246
tcx : TyCtxt < ' _ > ,
1258
1247
item_id : LocalDefId ,
1259
- ty_span : Span ,
1260
- unsized_handling : UnsizedHandling ,
1261
1248
) -> Result < ( ) , ErrorGuaranteed > {
1262
1249
enter_wf_checking_ctxt ( tcx, item_id, |wfcx| {
1263
1250
let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
1264
- let item_ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1265
-
1266
- let forbid_unsized = match unsized_handling {
1267
- UnsizedHandling :: Forbid => true ,
1268
- UnsizedHandling :: AllowIfForeignTail => {
1269
- let tail =
1270
- tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1271
- !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1272
- }
1251
+ let item_ty = wfcx. deeply_normalize ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1252
+
1253
+ let is_foreign_item = tcx. is_foreign_item ( item_id) ;
1254
+
1255
+ let forbid_unsized = !is_foreign_item || {
1256
+ let tail = tcx. struct_tail_for_codegen ( item_ty, wfcx. infcx . typing_env ( wfcx. param_env ) ) ;
1257
+ !matches ! ( tail. kind( ) , ty:: Foreign ( _) )
1273
1258
} ;
1274
1259
1275
- wfcx. register_wf_obligation ( ty_span , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1260
+ wfcx. register_wf_obligation ( DUMMY_SP , Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1276
1261
if forbid_unsized {
1277
1262
wfcx. register_bound (
1278
1263
traits:: ObligationCause :: new (
1279
- ty_span ,
1264
+ DUMMY_SP ,
1280
1265
wfcx. body_def_id ,
1281
1266
ObligationCauseCode :: SizedConstOrStatic ,
1282
1267
) ,
1283
1268
wfcx. param_env ,
1284
1269
item_ty,
1285
- tcx. require_lang_item ( LangItem :: Sized , ty_span ) ,
1270
+ tcx. require_lang_item ( LangItem :: Sized , tcx . def_span ( item_id ) ) ,
1286
1271
) ;
1287
1272
}
1288
1273
1289
1274
// Ensure that the end result is `Sync` in a non-thread local `static`.
1290
1275
let should_check_for_sync = tcx. static_mutability ( item_id. to_def_id ( ) )
1291
1276
== Some ( hir:: Mutability :: Not )
1292
- && !tcx . is_foreign_item ( item_id . to_def_id ( ) )
1277
+ && !is_foreign_item
1293
1278
&& !tcx. is_thread_local_static ( item_id. to_def_id ( ) ) ;
1294
1279
1295
1280
if should_check_for_sync {
1296
1281
wfcx. register_bound (
1297
1282
traits:: ObligationCause :: new (
1298
- ty_span ,
1283
+ DUMMY_SP ,
1299
1284
wfcx. body_def_id ,
1300
1285
ObligationCauseCode :: SharedStatic ,
1301
1286
) ,
1302
1287
wfcx. param_env ,
1303
1288
item_ty,
1304
- tcx. require_lang_item ( LangItem :: Sync , ty_span ) ,
1289
+ tcx. require_lang_item ( LangItem :: Sync , DUMMY_SP ) ,
1305
1290
) ;
1306
1291
}
1307
1292
Ok ( ( ) )
0 commit comments