@@ -951,16 +951,19 @@ pub(crate) fn check_associated_item(
951951 let ty = wfcx. deeply_normalize ( span, Some ( WellFormedLoc :: Ty ( def_id) ) , ty) ;
952952 wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
953953
954- if item. defaultness ( tcx) . has_value ( ) {
954+ let has_value = item. defaultness ( tcx) . has_value ( ) ;
955+ if find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: TypeConst ( _) ) {
956+ check_type_const ( wfcx, def_id, ty, has_value) ?;
957+ }
958+
959+ if has_value {
955960 let code = ObligationCauseCode :: SizedConstOrStatic ;
956961 wfcx. register_bound (
957962 ObligationCause :: new ( span, def_id, code) ,
958963 wfcx. param_env ,
959964 ty,
960965 tcx. require_lang_item ( LangItem :: Sized , span) ,
961966 ) ;
962-
963- check_const_item_rhs ( wfcx, def_id) ?;
964967 }
965968
966969 Ok ( ( ) )
@@ -1230,16 +1233,33 @@ pub(crate) fn check_static_item<'tcx>(
12301233}
12311234
12321235#[ instrument( level = "debug" , skip( wfcx) ) ]
1233- pub ( super ) fn check_const_item_rhs < ' tcx > (
1236+ pub ( super ) fn check_type_const < ' tcx > (
12341237 wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
12351238 def_id : LocalDefId ,
1239+ item_ty : Ty < ' tcx > ,
1240+ has_value : bool ,
12361241) -> Result < ( ) , ErrorGuaranteed > {
12371242 let tcx = wfcx. tcx ( ) ;
1238- if find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: TypeConst ( _) ) {
1243+ let span = tcx. def_span ( def_id) ;
1244+
1245+ wfcx. register_bound (
1246+ ObligationCause :: new ( span, def_id, ObligationCauseCode :: ConstParam ( item_ty) ) ,
1247+ wfcx. param_env ,
1248+ item_ty,
1249+ tcx. require_lang_item ( LangItem :: ConstParamTy , span) ,
1250+ ) ;
1251+
1252+ if has_value {
12391253 let raw_ct = tcx. const_of_item ( def_id) . instantiate_identity ( ) ;
1240- let span = tcx. def_span ( def_id) ;
12411254 let norm_ct = wfcx. deeply_normalize ( span, Some ( WellFormedLoc :: Ty ( def_id) ) , raw_ct) ;
12421255 wfcx. register_wf_obligation ( span, Some ( WellFormedLoc :: Ty ( def_id) ) , norm_ct. into ( ) ) ;
1256+
1257+ wfcx. register_obligation ( Obligation :: new (
1258+ tcx,
1259+ ObligationCause :: new ( span, def_id, ObligationCauseCode :: WellFormed ( None ) ) ,
1260+ wfcx. param_env ,
1261+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: ConstArgHasType ( norm_ct, item_ty) ) ,
1262+ ) ) ;
12431263 }
12441264 Ok ( ( ) )
12451265}
0 commit comments