@@ -298,11 +298,9 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
298
298
check_item_fn ( tcx, def_id, ident, item. span , sig. decl )
299
299
}
300
300
hir:: ItemKind :: Static ( _, ty, ..) => {
301
- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
302
- }
303
- hir:: ItemKind :: Const ( _, ty, ..) => {
304
- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
301
+ check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
305
302
}
303
+ hir:: ItemKind :: Const ( _, ty, ..) => check_const_item ( tcx, def_id, ty. span , item. span ) ,
306
304
hir:: ItemKind :: Struct ( _, _, hir_generics) => {
307
305
let res = check_type_defn ( tcx, item, false ) ;
308
306
check_variances_for_type_defn ( tcx, item, hir_generics) ;
@@ -366,7 +364,7 @@ fn check_foreign_item<'tcx>(
366
364
check_item_fn ( tcx, def_id, item. ident , item. span , sig. decl )
367
365
}
368
366
hir:: ForeignItemKind :: Static ( ty, ..) => {
369
- check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
367
+ check_static_item ( tcx, def_id, ty. span , UnsizedHandling :: AllowIfForeignTail )
370
368
}
371
369
hir:: ForeignItemKind :: Type => Ok ( ( ) ) ,
372
370
}
@@ -1331,14 +1329,13 @@ enum UnsizedHandling {
1331
1329
AllowIfForeignTail ,
1332
1330
}
1333
1331
1334
- fn check_item_type (
1332
+ #[ instrument( level = "debug" , skip( tcx, ty_span, unsized_handling) ) ]
1333
+ fn check_static_item (
1335
1334
tcx : TyCtxt < ' _ > ,
1336
1335
item_id : LocalDefId ,
1337
1336
ty_span : Span ,
1338
1337
unsized_handling : UnsizedHandling ,
1339
1338
) -> Result < ( ) , ErrorGuaranteed > {
1340
- debug ! ( "check_item_type: {:?}" , item_id) ;
1341
-
1342
1339
enter_wf_checking_ctxt ( tcx, ty_span, item_id, |wfcx| {
1343
1340
let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
1344
1341
let item_ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
@@ -1388,6 +1385,34 @@ fn check_item_type(
1388
1385
} )
1389
1386
}
1390
1387
1388
+ fn check_const_item (
1389
+ tcx : TyCtxt < ' _ > ,
1390
+ def_id : LocalDefId ,
1391
+ ty_span : Span ,
1392
+ item_span : Span ,
1393
+ ) -> Result < ( ) , ErrorGuaranteed > {
1394
+ enter_wf_checking_ctxt ( tcx, ty_span, def_id, |wfcx| {
1395
+ let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1396
+ let ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( def_id) ) , ty) ;
1397
+
1398
+ wfcx. register_wf_obligation ( ty_span, Some ( WellFormedLoc :: Ty ( def_id) ) , ty. into ( ) ) ;
1399
+ wfcx. register_bound (
1400
+ traits:: ObligationCause :: new (
1401
+ ty_span,
1402
+ wfcx. body_def_id ,
1403
+ ObligationCauseCode :: SizedConstOrStatic ,
1404
+ ) ,
1405
+ wfcx. param_env ,
1406
+ ty,
1407
+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
1408
+ ) ;
1409
+
1410
+ check_where_clauses ( wfcx, item_span, def_id) ;
1411
+
1412
+ Ok ( ( ) )
1413
+ } )
1414
+ }
1415
+
1391
1416
#[ instrument( level = "debug" , skip( tcx, hir_self_ty, hir_trait_ref) ) ]
1392
1417
fn check_impl < ' tcx > (
1393
1418
tcx : TyCtxt < ' tcx > ,
0 commit comments