@@ -185,17 +185,17 @@ where
185185}
186186
187187fn 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) ;
189189 let node = tcx. hir_node_by_def_id ( def_id) ;
190- let mut res = match node {
190+ res = res . and ( match node {
191191 hir:: Node :: Crate ( _) => bug ! ( "check_well_formed cannot be applied to the crate root" ) ,
192192 hir:: Node :: Item ( item) => check_item ( tcx, item) ,
193193 hir:: Node :: TraitItem ( item) => check_trait_item ( tcx, item) ,
194194 hir:: Node :: ImplItem ( item) => check_impl_item ( tcx, item) ,
195195 hir:: Node :: ForeignItem ( item) => check_foreign_item ( tcx, item) ,
196196 hir:: Node :: ConstBlock ( _) | hir:: Node :: Expr ( _) | hir:: Node :: OpaqueTy ( _) => Ok ( ( ) ) ,
197197 _ => unreachable ! ( "{node:?}" ) ,
198- } ;
198+ } ) ;
199199
200200 for param in & tcx. generics_of ( def_id) . own_params {
201201 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<()
291291 res
292292 }
293293 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- }
297294 hir:: ItemKind :: Const ( _, _, ty, _) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
298295 hir:: ItemKind :: Struct ( _, generics, _) => {
299296 let res = check_type_defn ( tcx, item, false ) ;
@@ -347,10 +344,7 @@ fn check_foreign_item<'tcx>(
347344
348345 match item. kind {
349346 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 ( ( ) ) ,
354348 }
355349}
356350
@@ -1247,61 +1241,52 @@ fn check_item_fn(
12471241 } )
12481242}
12491243
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 (
12571246 tcx : TyCtxt < ' _ > ,
12581247 item_id : LocalDefId ,
1259- ty_span : Span ,
1260- unsized_handling : UnsizedHandling ,
12611248) -> Result < ( ) , ErrorGuaranteed > {
12621249 enter_wf_checking_ctxt ( tcx, item_id, |wfcx| {
12631250 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 ( _) )
12731258 } ;
12741259
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 ( ) ) ;
12761261 if forbid_unsized {
12771262 wfcx. register_bound (
12781263 traits:: ObligationCause :: new (
1279- ty_span ,
1264+ DUMMY_SP ,
12801265 wfcx. body_def_id ,
12811266 ObligationCauseCode :: SizedConstOrStatic ,
12821267 ) ,
12831268 wfcx. param_env ,
12841269 item_ty,
1285- tcx. require_lang_item ( LangItem :: Sized , ty_span ) ,
1270+ tcx. require_lang_item ( LangItem :: Sized , tcx . def_span ( item_id ) ) ,
12861271 ) ;
12871272 }
12881273
12891274 // Ensure that the end result is `Sync` in a non-thread local `static`.
12901275 let should_check_for_sync = tcx. static_mutability ( item_id. to_def_id ( ) )
12911276 == Some ( hir:: Mutability :: Not )
1292- && !tcx . is_foreign_item ( item_id . to_def_id ( ) )
1277+ && !is_foreign_item
12931278 && !tcx. is_thread_local_static ( item_id. to_def_id ( ) ) ;
12941279
12951280 if should_check_for_sync {
12961281 wfcx. register_bound (
12971282 traits:: ObligationCause :: new (
1298- ty_span ,
1283+ DUMMY_SP ,
12991284 wfcx. body_def_id ,
13001285 ObligationCauseCode :: SharedStatic ,
13011286 ) ,
13021287 wfcx. param_env ,
13031288 item_ty,
1304- tcx. require_lang_item ( LangItem :: Sync , ty_span ) ,
1289+ tcx. require_lang_item ( LangItem :: Sync , DUMMY_SP ) ,
13051290 ) ;
13061291 }
13071292 Ok ( ( ) )
0 commit comments