@@ -186,17 +186,17 @@ where
186186}
187187
188188fn 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) ;
190190 let node = tcx. hir_node_by_def_id ( def_id) ;
191- let mut res = match node {
191+ res = res . and ( match node {
192192 hir:: Node :: Crate ( _) => bug ! ( "check_well_formed cannot be applied to the crate root" ) ,
193193 hir:: Node :: Item ( item) => check_item ( tcx, item) ,
194194 hir:: Node :: TraitItem ( item) => check_trait_item ( tcx, item) ,
195195 hir:: Node :: ImplItem ( item) => check_impl_item ( tcx, item) ,
196196 hir:: Node :: ForeignItem ( item) => check_foreign_item ( tcx, item) ,
197197 hir:: Node :: OpaqueTy ( _) => Ok ( ( ) ) ,
198198 _ => unreachable ! ( "{node:?}" ) ,
199- } ;
199+ } ) ;
200200
201201 for param in & tcx. generics_of ( def_id) . own_params {
202202 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<()
292292 res
293293 }
294294 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- }
298295 hir:: ItemKind :: Const ( _, _, ty, _) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
299296 hir:: ItemKind :: Struct ( _, generics, _) => {
300297 let res = check_type_defn ( tcx, item, false ) ;
@@ -350,10 +347,7 @@ fn check_foreign_item<'tcx>(
350347
351348 match item. kind {
352349 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 ( ( ) ) ,
357351 }
358352}
359353
@@ -1315,61 +1309,52 @@ fn check_item_fn(
13151309 } )
13161310}
13171311
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 (
13251314 tcx : TyCtxt < ' _ > ,
13261315 item_id : LocalDefId ,
1327- ty_span : Span ,
1328- unsized_handling : UnsizedHandling ,
13291316) -> Result < ( ) , ErrorGuaranteed > {
13301317 enter_wf_checking_ctxt ( tcx, item_id, |wfcx| {
13311318 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 ( _) )
13411326 } ;
13421327
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 ( ) ) ;
13441329 if forbid_unsized {
13451330 wfcx. register_bound (
13461331 traits:: ObligationCause :: new (
1347- ty_span ,
1332+ DUMMY_SP ,
13481333 wfcx. body_def_id ,
13491334 ObligationCauseCode :: SizedConstOrStatic ,
13501335 ) ,
13511336 wfcx. param_env ,
13521337 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 ) ) ) ,
13541339 ) ;
13551340 }
13561341
13571342 // Ensure that the end result is `Sync` in a non-thread local `static`.
13581343 let should_check_for_sync = tcx. static_mutability ( item_id. to_def_id ( ) )
13591344 == Some ( hir:: Mutability :: Not )
1360- && !tcx . is_foreign_item ( item_id . to_def_id ( ) )
1345+ && !is_foreign_item
13611346 && !tcx. is_thread_local_static ( item_id. to_def_id ( ) ) ;
13621347
13631348 if should_check_for_sync {
13641349 wfcx. register_bound (
13651350 traits:: ObligationCause :: new (
1366- ty_span ,
1351+ DUMMY_SP ,
13671352 wfcx. body_def_id ,
13681353 ObligationCauseCode :: SharedStatic ,
13691354 ) ,
13701355 wfcx. param_env ,
13711356 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 ) ) ) ,
13731358 ) ;
13741359 }
13751360 Ok ( ( ) )
0 commit comments