@@ -268,11 +268,9 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
268268 check_item_fn ( tcx, def_id, ident, item. span , sig. decl )
269269 }
270270 hir:: ItemKind :: Static ( _, ty, ..) => {
271- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
272- }
273- hir:: ItemKind :: Const ( _, ty, ..) => {
274- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
271+ check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
275272 }
273+ hir:: ItemKind :: Const ( _, ty, ..) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
276274 hir:: ItemKind :: Struct ( _, _, hir_generics) => {
277275 let res = check_type_defn ( tcx, item, false ) ;
278276 check_variances_for_type_defn ( tcx, item, hir_generics) ;
@@ -335,7 +333,7 @@ fn check_foreign_item<'tcx>(
335333 check_item_fn ( tcx, def_id, item. ident , item. span , sig. decl )
336334 }
337335 hir:: ForeignItemKind :: Static ( ty, ..) => {
338- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
336+ check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
339337 }
340338 hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
341339 }
@@ -1300,14 +1298,13 @@ enum UnsizedHandling {
13001298 AllowIfForeignTail ,
13011299}
13021300
1303- fn check_item_type (
1301+ #[ instrument( level = "debug" , skip( tcx, ty_span, unsized_handling) ) ]
1302+ fn check_static_item (
13041303 tcx : TyCtxt < ' _ > ,
13051304 item_id : LocalDefId ,
13061305 ty_span : Span ,
13071306 unsized_handling : UnsizedHandling ,
13081307) -> Result < ( ) , ErrorGuaranteed > {
1309- debug ! ( "check_item_type: {:?}" , item_id) ;
1310-
13111308 enter_wf_checking_ctxt ( tcx, ty_span, item_id, |wfcx| {
13121309 let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
13131310 let item_ty = wfcx. normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
@@ -1357,6 +1354,34 @@ fn check_item_type(
13571354 } )
13581355}
13591356
1357+ fn check_const_item (
1358+ tcx : TyCtxt < ' _ > ,
1359+ def_id : LocalDefId ,
1360+ ty_span : Span ,
1361+ item_span : Span ,
1362+ ) -> Result < ( ) , ErrorGuaranteed > {
1363+ enter_wf_checking_ctxt ( tcx, ty_span, def_id, |wfcx| {
1364+ let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1365+ let ty = wfcx. normalize ( ty_span, Some ( WellFormedLoc :: Ty ( def_id) ) , ty) ;
1366+
1367+ wfcx. register_wf_obligation ( ty_span, Some ( WellFormedLoc :: Ty ( def_id) ) , ty. into ( ) ) ;
1368+ wfcx. register_bound (
1369+ traits:: ObligationCause :: new (
1370+ ty_span,
1371+ wfcx. body_def_id ,
1372+ ObligationCauseCode :: SizedConstOrStatic ,
1373+ ) ,
1374+ wfcx. param_env ,
1375+ ty,
1376+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
1377+ ) ;
1378+
1379+ check_where_clauses ( wfcx, item_span, def_id) ;
1380+
1381+ Ok ( ( ) )
1382+ } )
1383+ }
1384+
13601385#[ instrument( level = "debug" , skip( tcx, hir_self_ty, hir_trait_ref) ) ]
13611386fn check_impl < ' tcx > (
13621387 tcx : TyCtxt < ' tcx > ,
0 commit comments