@@ -76,6 +76,36 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
7676 )
7777 }
7878
79+ /// Convenience function to *deeply* normalize during wfcheck. In the old solver,
80+ /// this just dispatches to [`WfCheckingCtxt::normalize`], but in the new solver
81+ /// this calls `deeply_normalize` and reports errors if they are encountered.
82+ ///
83+ /// This function should be called in favor of `normalize` in cases where we will
84+ /// then check the well-formedness of the type, since we only use the normalized
85+ /// signature types for implied bounds when checking regions.
86+ // FIXME(-Znext-solver): This should be removed when we compute implied outlives
87+ // bounds using the unnormalized signature of the function we're checking.
88+ fn deeply_normalize < T > ( & self , span : Span , loc : Option < WellFormedLoc > , value : T ) -> T
89+ where
90+ T : TypeFoldable < TyCtxt < ' tcx > > ,
91+ {
92+ if self . infcx . next_trait_solver ( ) {
93+ match self . ocx . deeply_normalize (
94+ & ObligationCause :: new ( span, self . body_def_id , ObligationCauseCode :: WellFormed ( loc) ) ,
95+ self . param_env ,
96+ value. clone ( ) ,
97+ ) {
98+ Ok ( value) => value,
99+ Err ( errors) => {
100+ self . infcx . err_ctxt ( ) . report_fulfillment_errors ( errors) ;
101+ value
102+ }
103+ }
104+ } else {
105+ self . normalize ( span, loc, value)
106+ }
107+ }
108+
79109 fn register_wf_obligation ( & self , span : Span , loc : Option < WellFormedLoc > , term : ty:: Term < ' tcx > ) {
80110 let cause = traits:: ObligationCause :: new (
81111 span,
@@ -297,7 +327,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
297327 {
298328 let res = enter_wf_checking_ctxt ( tcx, item. span , def_id, |wfcx| {
299329 let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
300- let item_ty = wfcx. normalize ( hir_ty. span , Some ( WellFormedLoc :: Ty ( def_id) ) , ty) ;
330+ let item_ty =
331+ wfcx. deeply_normalize ( hir_ty. span , Some ( WellFormedLoc :: Ty ( def_id) ) , ty) ;
301332 wfcx. register_wf_obligation (
302333 hir_ty. span ,
303334 Some ( WellFormedLoc :: Ty ( def_id) ) ,
@@ -1073,7 +1104,7 @@ fn check_associated_item(
10731104 match item. kind {
10741105 ty:: AssocKind :: Const { .. } => {
10751106 let ty = tcx. type_of ( item. def_id ) . instantiate_identity ( ) ;
1076- let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1107+ let ty = wfcx. deeply_normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
10771108 wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
10781109 check_sized_if_body (
10791110 wfcx,
@@ -1102,7 +1133,7 @@ fn check_associated_item(
11021133 }
11031134 if item. defaultness ( tcx) . has_value ( ) {
11041135 let ty = tcx. type_of ( item. def_id ) . instantiate_identity ( ) ;
1105- let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1136+ let ty = wfcx. deeply_normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
11061137 wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
11071138 }
11081139 Ok ( ( ) )
@@ -1149,7 +1180,7 @@ fn check_type_defn<'tcx>(
11491180 let field_id = field. did . expect_local ( ) ;
11501181 let hir:: FieldDef { ty : hir_ty, .. } =
11511182 tcx. hir_node_by_def_id ( field_id) . expect_field ( ) ;
1152- let ty = wfcx. normalize (
1183+ let ty = wfcx. deeply_normalize (
11531184 hir_ty. span ,
11541185 None ,
11551186 tcx. type_of ( field. did ) . instantiate_identity ( ) ,
@@ -1310,7 +1341,7 @@ fn check_item_type(
13101341
13111342 enter_wf_checking_ctxt ( tcx, ty_span, item_id, |wfcx| {
13121343 let ty = tcx. type_of ( item_id) . instantiate_identity ( ) ;
1313- let item_ty = wfcx. normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1344+ let item_ty = wfcx. deeply_normalize ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
13141345
13151346 let forbid_unsized = match unsized_handling {
13161347 UnsizedHandling :: Forbid => true ,
@@ -1375,7 +1406,7 @@ fn check_impl<'tcx>(
13751406 // other `Foo` impls are incoherent.
13761407 tcx. ensure_ok ( ) . coherent_trait ( trait_ref. def_id ) ?;
13771408 let trait_span = hir_trait_ref. path . span ;
1378- let trait_ref = wfcx. normalize (
1409+ let trait_ref = wfcx. deeply_normalize (
13791410 trait_span,
13801411 Some ( WellFormedLoc :: Ty ( item. hir_id ( ) . expect_owner ( ) . def_id ) ) ,
13811412 trait_ref,
@@ -1435,7 +1466,7 @@ fn check_impl<'tcx>(
14351466 }
14361467 None => {
14371468 let self_ty = tcx. type_of ( item. owner_id ) . instantiate_identity ( ) ;
1438- let self_ty = wfcx. normalize (
1469+ let self_ty = wfcx. deeply_normalize (
14391470 item. span ,
14401471 Some ( WellFormedLoc :: Ty ( item. hir_id ( ) . expect_owner ( ) . def_id ) ) ,
14411472 self_ty,
@@ -1640,7 +1671,7 @@ fn check_fn_or_method<'tcx>(
16401671
16411672 sig. inputs_and_output =
16421673 tcx. mk_type_list_from_iter ( sig. inputs_and_output . iter ( ) . enumerate ( ) . map ( |( idx, ty) | {
1643- wfcx. normalize (
1674+ wfcx. deeply_normalize (
16441675 arg_span ( idx) ,
16451676 Some ( WellFormedLoc :: Param {
16461677 function : def_id,
0 commit comments