@@ -76,6 +76,36 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
76
76
)
77
77
}
78
78
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
+
79
109
fn register_wf_obligation ( & self , span : Span , loc : Option < WellFormedLoc > , term : ty:: Term < ' tcx > ) {
80
110
let cause = traits:: ObligationCause :: new (
81
111
span,
@@ -297,7 +327,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
297
327
{
298
328
let res = enter_wf_checking_ctxt ( tcx, item. span , def_id, |wfcx| {
299
329
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) ;
301
332
wfcx. register_wf_obligation (
302
333
hir_ty. span ,
303
334
Some ( WellFormedLoc :: Ty ( def_id) ) ,
@@ -1073,7 +1104,7 @@ fn check_associated_item(
1073
1104
match item. kind {
1074
1105
ty:: AssocKind :: Const { .. } => {
1075
1106
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) ;
1077
1108
wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
1078
1109
check_sized_if_body (
1079
1110
wfcx,
@@ -1102,7 +1133,7 @@ fn check_associated_item(
1102
1133
}
1103
1134
if item. defaultness ( tcx) . has_value ( ) {
1104
1135
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) ;
1106
1137
wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
1107
1138
}
1108
1139
Ok ( ( ) )
@@ -1149,7 +1180,7 @@ fn check_type_defn<'tcx>(
1149
1180
let field_id = field. did . expect_local ( ) ;
1150
1181
let hir:: FieldDef { ty : hir_ty, .. } =
1151
1182
tcx. hir_node_by_def_id ( field_id) . expect_field ( ) ;
1152
- let ty = wfcx. normalize (
1183
+ let ty = wfcx. deeply_normalize (
1153
1184
hir_ty. span ,
1154
1185
None ,
1155
1186
tcx. type_of ( field. did ) . instantiate_identity ( ) ,
@@ -1310,7 +1341,7 @@ fn check_item_type(
1310
1341
1311
1342
enter_wf_checking_ctxt ( tcx, ty_span, item_id, |wfcx| {
1312
1343
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) ;
1314
1345
1315
1346
let forbid_unsized = match unsized_handling {
1316
1347
UnsizedHandling :: Forbid => true ,
@@ -1375,7 +1406,7 @@ fn check_impl<'tcx>(
1375
1406
// other `Foo` impls are incoherent.
1376
1407
tcx. ensure_ok ( ) . coherent_trait ( trait_ref. def_id ) ?;
1377
1408
let trait_span = hir_trait_ref. path . span ;
1378
- let trait_ref = wfcx. normalize (
1409
+ let trait_ref = wfcx. deeply_normalize (
1379
1410
trait_span,
1380
1411
Some ( WellFormedLoc :: Ty ( item. hir_id ( ) . expect_owner ( ) . def_id ) ) ,
1381
1412
trait_ref,
@@ -1435,7 +1466,7 @@ fn check_impl<'tcx>(
1435
1466
}
1436
1467
None => {
1437
1468
let self_ty = tcx. type_of ( item. owner_id ) . instantiate_identity ( ) ;
1438
- let self_ty = wfcx. normalize (
1469
+ let self_ty = wfcx. deeply_normalize (
1439
1470
item. span ,
1440
1471
Some ( WellFormedLoc :: Ty ( item. hir_id ( ) . expect_owner ( ) . def_id ) ) ,
1441
1472
self_ty,
@@ -1640,7 +1671,7 @@ fn check_fn_or_method<'tcx>(
1640
1671
1641
1672
sig. inputs_and_output =
1642
1673
tcx. mk_type_list_from_iter ( sig. inputs_and_output . iter ( ) . enumerate ( ) . map ( |( idx, ty) | {
1643
- wfcx. normalize (
1674
+ wfcx. deeply_normalize (
1644
1675
arg_span ( idx) ,
1645
1676
Some ( WellFormedLoc :: Param {
1646
1677
function : def_id,
0 commit comments