@@ -1521,11 +1521,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15211521 } ;
15221522
15231523 let mut result = ProbeResult :: Match ;
1524- let mut xform_ret_ty = probe. xform_ret_ty ;
1525- debug ! ( ?xform_ret_ty) ;
1526-
15271524 let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
15281525
1526+ let xform_ret_ty = if let Some ( xform_ret_ty) = probe. xform_ret_ty {
1527+ // `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1528+ // see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1529+ // for why this is necessary
1530+ let InferOk {
1531+ value : normalized_xform_ret_ty,
1532+ obligations : normalization_obligations,
1533+ } = self . fcx . at ( & cause, self . param_env ) . normalize ( xform_ret_ty) ;
1534+ debug ! ( "xform_ret_ty after normalization: {:?}" , normalized_xform_ret_ty) ;
1535+
1536+ for o in normalization_obligations {
1537+ if !self . predicate_may_hold ( & o) {
1538+ possibly_unsatisfied_predicates. push ( ( o. predicate , None , Some ( o. cause ) ) ) ;
1539+ result = ProbeResult :: NoMatch ;
1540+ }
1541+ }
1542+
1543+ Some ( normalized_xform_ret_ty)
1544+ } else {
1545+ None
1546+ } ;
1547+
15291548 let mut parent_pred = None ;
15301549
15311550 // If so, impls may carry other conditions (e.g., where
@@ -1534,16 +1553,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15341553 // don't have enough information to fully evaluate).
15351554 match probe. kind {
15361555 InherentImplCandidate ( ref substs, ref ref_obligations) => {
1537- // `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1538- // see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1539- // for why this is necessary
1540- let InferOk {
1541- value : normalized_xform_ret_ty,
1542- obligations : normalization_obligations,
1543- } = self . fcx . at ( & cause, self . param_env ) . normalize ( probe. xform_ret_ty ) ;
1544- xform_ret_ty = normalized_xform_ret_ty;
1545- debug ! ( "xform_ret_ty after normalization: {:?}" , xform_ret_ty) ;
1546-
15471556 // Check whether the impl imposes obligations we have to worry about.
15481557 let impl_def_id = probe. item . container_id ( self . tcx ) ;
15491558 let impl_bounds = self . tcx . predicates_of ( impl_def_id) ;
@@ -1554,15 +1563,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15541563
15551564 // Convert the bounds into obligations.
15561565 let impl_obligations = traits:: predicates_for_generics (
1557- move |_, _| cause. clone ( ) ,
1566+ |_, _| cause. clone ( ) ,
15581567 self . param_env ,
15591568 impl_bounds,
15601569 ) ;
15611570
15621571 let candidate_obligations = impl_obligations
15631572 . chain ( norm_obligations. into_iter ( ) )
1564- . chain ( ref_obligations. iter ( ) . cloned ( ) )
1565- . chain ( normalization_obligations. into_iter ( ) ) ;
1573+ . chain ( ref_obligations. iter ( ) . cloned ( ) ) ;
15661574
15671575 // Evaluate those obligations to see if they might possibly hold.
15681576 for o in candidate_obligations {
@@ -1597,7 +1605,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15971605 ty:: Binder :: dummy ( trait_ref) . without_const ( ) . to_predicate ( self . tcx ) ;
15981606 parent_pred = Some ( predicate) ;
15991607 let obligation =
1600- traits:: Obligation :: new ( self . tcx , cause, self . param_env , predicate) ;
1608+ traits:: Obligation :: new ( self . tcx , cause. clone ( ) , self . param_env , predicate) ;
16011609 if !self . predicate_may_hold ( & obligation) {
16021610 result = ProbeResult :: NoMatch ;
16031611 if self . probe ( |_| {
@@ -1656,21 +1664,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16561664 }
16571665 }
16581666
1659- if let ProbeResult :: Match = result {
1660- if let ( Some ( return_ty) , Some ( xform_ret_ty) ) = ( self . return_type , xform_ret_ty) {
1661- let xform_ret_ty = self . resolve_vars_if_possible ( xform_ret_ty) ;
1662- debug ! (
1663- "comparing return_ty {:?} with xform ret ty {:?}" ,
1664- return_ty, probe. xform_ret_ty
1665- ) ;
1666- if self
1667- . at ( & ObligationCause :: dummy ( ) , self . param_env )
1668- . define_opaque_types ( false )
1669- . sup ( return_ty, xform_ret_ty)
1670- . is_err ( )
1671- {
1672- return ProbeResult :: BadReturnType ;
1673- }
1667+ if let ProbeResult :: Match = result
1668+ && let Some ( return_ty) = self . return_type
1669+ && let Some ( xform_ret_ty) = xform_ret_ty
1670+ {
1671+ debug ! (
1672+ "comparing return_ty {:?} with xform ret ty {:?}" ,
1673+ return_ty, xform_ret_ty
1674+ ) ;
1675+ if let ProbeResult :: Match = result
1676+ && self
1677+ . at ( & ObligationCause :: dummy ( ) , self . param_env )
1678+ . define_opaque_types ( false )
1679+ . sup ( return_ty, xform_ret_ty)
1680+ . is_err ( )
1681+ {
1682+ return ProbeResult :: BadReturnType ;
16741683 }
16751684 }
16761685
0 commit comments