@@ -38,6 +38,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
3838 CandidateStep , MethodAutoderefStepsResult ,
3939} ;
4040use rustc_trait_selection:: traits:: query:: CanonicalTyGoal ;
41+ use rustc_trait_selection:: traits:: NormalizeExt ;
4142use rustc_trait_selection:: traits:: ObligationCtxt ;
4243use rustc_trait_selection:: traits:: { self , ObligationCause } ;
4344use std:: cell:: RefCell ;
@@ -1376,7 +1377,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13761377 let impl_ty = self . tcx . type_of ( impl_def_id) . instantiate ( self . tcx , impl_args) ;
13771378 ( xform_self_ty, xform_ret_ty) =
13781379 self . xform_self_ty ( probe. item , impl_ty, impl_args) ;
1379- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1380+ let InferOk { value : normalized, mut obligations } =
1381+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1382+ xform_self_ty = normalized;
13801383 // FIXME: Make this `ocx.sup` once we define opaques more eagerly.
13811384 match self . at ( cause, self . param_env ) . sup (
13821385 DefineOpaqueTypes :: No ,
@@ -1398,7 +1401,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13981401 let impl_bounds =
13991402 self . tcx . predicates_of ( impl_def_id) . instantiate ( self . tcx , impl_args) ;
14001403 let impl_bounds = ocx. normalize ( cause, self . param_env , impl_bounds) ;
1401- for obligation in traits:: predicates_for_generics (
1404+ obligations . extend ( traits:: predicates_for_generics (
14021405 |idx, span| {
14031406 let code = if span. is_dummy ( ) {
14041407 traits:: ExprItemObligation ( impl_def_id, self . scope_expr_id , idx)
@@ -1414,7 +1417,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14141417 } ,
14151418 self . param_env ,
14161419 impl_bounds,
1417- ) {
1420+ ) ) ;
1421+
1422+ for obligation in obligations {
14181423 if self . infcx . next_trait_solver ( ) {
14191424 ocx. register_obligation ( obligation) ;
14201425 } else {
@@ -1460,7 +1465,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14601465 let trait_ref = ocx. normalize ( cause, self . param_env , trait_ref) ;
14611466 ( xform_self_ty, xform_ret_ty) =
14621467 self . xform_self_ty ( probe. item , trait_ref. self_ty ( ) , trait_ref. args ) ;
1463- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1468+
1469+ let InferOk { value : normalized, obligations : normalize_obligations } =
1470+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1471+ xform_self_ty = normalized;
1472+
14641473 // FIXME: Make this `ocx.sup` once we define opaques more eagerly.
14651474 match self . at ( cause, self . param_env ) . sup (
14661475 DefineOpaqueTypes :: No ,
@@ -1475,6 +1484,33 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14751484 return ProbeResult :: NoMatch ;
14761485 }
14771486 }
1487+
1488+ for obligation in normalize_obligations {
1489+ if self . infcx . next_trait_solver ( ) {
1490+ ocx. register_obligation ( obligation) ;
1491+ } else {
1492+ match self . infcx . evaluate_obligation_no_overflow ( & obligation) {
1493+ EvaluationResult :: EvaluatedToOk => {
1494+ // No side-effects, no need to register obligations.
1495+ }
1496+ EvaluationResult :: EvaluatedToOkModuloRegions
1497+ | EvaluationResult :: EvaluatedToOkModuloOpaqueTypes
1498+ | EvaluationResult :: EvaluatedToAmbig
1499+ | EvaluationResult :: EvaluatedToAmbigStackDependent => {
1500+ ocx. register_obligation ( obligation) ;
1501+ }
1502+ EvaluationResult :: EvaluatedToErr => {
1503+ result = ProbeResult :: NoMatch ;
1504+ possibly_unsatisfied_predicates. push ( (
1505+ self . resolve_vars_if_possible ( obligation. predicate ) ,
1506+ None ,
1507+ Some ( obligation. cause . clone ( ) ) ,
1508+ ) ) ;
1509+ }
1510+ }
1511+ }
1512+ }
1513+
14781514 let obligation = traits:: Obligation :: new (
14791515 self . tcx ,
14801516 cause. clone ( ) ,
@@ -1527,7 +1563,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15271563 ) ;
15281564 ( xform_self_ty, xform_ret_ty) =
15291565 self . xform_self_ty ( probe. item , trait_ref. self_ty ( ) , trait_ref. args ) ;
1530- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1566+ let InferOk { value : normalized, obligations : normalize_obligations } =
1567+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1568+ xform_self_ty = normalized;
1569+
15311570 // FIXME: Make this `ocx.sup` once we define opaques more eagerly.
15321571 match self . at ( cause, self . param_env ) . sup (
15331572 DefineOpaqueTypes :: No ,
@@ -1542,6 +1581,32 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15421581 return ProbeResult :: NoMatch ;
15431582 }
15441583 }
1584+
1585+ for obligation in normalize_obligations {
1586+ if self . infcx . next_trait_solver ( ) {
1587+ ocx. register_obligation ( obligation) ;
1588+ } else {
1589+ match self . infcx . evaluate_obligation_no_overflow ( & obligation) {
1590+ EvaluationResult :: EvaluatedToOk => {
1591+ // No side-effects, no need to register obligations.
1592+ }
1593+ EvaluationResult :: EvaluatedToOkModuloRegions
1594+ | EvaluationResult :: EvaluatedToOkModuloOpaqueTypes
1595+ | EvaluationResult :: EvaluatedToAmbig
1596+ | EvaluationResult :: EvaluatedToAmbigStackDependent => {
1597+ ocx. register_obligation ( obligation) ;
1598+ }
1599+ EvaluationResult :: EvaluatedToErr => {
1600+ result = ProbeResult :: NoMatch ;
1601+ possibly_unsatisfied_predicates. push ( (
1602+ self . resolve_vars_if_possible ( obligation. predicate ) ,
1603+ None ,
1604+ Some ( obligation. cause . clone ( ) ) ,
1605+ ) ) ;
1606+ }
1607+ }
1608+ }
1609+ }
15451610 }
15461611 }
15471612
0 commit comments