@@ -1523,29 +1523,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1523
1523
} ;
1524
1524
1525
1525
let mut result = ProbeResult :: Match ;
1526
- let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
1527
-
1528
- let xform_ret_ty = if let Some ( xform_ret_ty) = probe. xform_ret_ty {
1529
- // `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1530
- // see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1531
- // for why this is necessary
1532
- let InferOk {
1533
- value : normalized_xform_ret_ty,
1534
- obligations : normalization_obligations,
1535
- } = self . fcx . at ( & cause, self . param_env ) . normalize ( xform_ret_ty) ;
1536
- debug ! ( "xform_ret_ty after normalization: {:?}" , normalized_xform_ret_ty) ;
1537
-
1538
- for o in normalization_obligations {
1539
- if !self . predicate_may_hold ( & o) {
1540
- possibly_unsatisfied_predicates. push ( ( o. predicate , None , Some ( o. cause ) ) ) ;
1541
- result = ProbeResult :: NoMatch ;
1542
- }
1543
- }
1526
+ let mut xform_ret_ty = probe. xform_ret_ty ;
1527
+ debug ! ( ?xform_ret_ty) ;
1544
1528
1545
- Some ( normalized_xform_ret_ty)
1546
- } else {
1547
- None
1548
- } ;
1529
+ let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
1549
1530
1550
1531
let mut parent_pred = None ;
1551
1532
@@ -1555,6 +1536,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1555
1536
// don't have enough information to fully evaluate).
1556
1537
match probe. kind {
1557
1538
InherentImplCandidate ( ref substs, ref ref_obligations) => {
1539
+ // `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1540
+ // see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1541
+ // for why this is necessary
1542
+ let InferOk {
1543
+ value : normalized_xform_ret_ty,
1544
+ obligations : normalization_obligations,
1545
+ } = self . fcx . at ( & cause, self . param_env ) . normalize ( xform_ret_ty) ;
1546
+ xform_ret_ty = normalized_xform_ret_ty;
1547
+ debug ! ( "xform_ret_ty after normalization: {:?}" , xform_ret_ty) ;
1548
+
1558
1549
// Check whether the impl imposes obligations we have to worry about.
1559
1550
let impl_def_id = probe. item . container_id ( self . tcx ) ;
1560
1551
let impl_bounds = self . tcx . predicates_of ( impl_def_id) ;
@@ -1572,7 +1563,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1572
1563
1573
1564
let candidate_obligations = impl_obligations
1574
1565
. chain ( norm_obligations. into_iter ( ) )
1575
- . chain ( ref_obligations. iter ( ) . cloned ( ) ) ;
1566
+ . chain ( ref_obligations. iter ( ) . cloned ( ) )
1567
+ . chain ( normalization_obligations. into_iter ( ) ) ;
1576
1568
1577
1569
// Evaluate those obligations to see if they might possibly hold.
1578
1570
for o in candidate_obligations {
@@ -1668,8 +1660,33 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1668
1660
1669
1661
if let ProbeResult :: Match = result
1670
1662
&& let Some ( return_ty) = self . return_type
1671
- && let Some ( xform_ret_ty) = xform_ret_ty
1663
+ && let Some ( mut xform_ret_ty) = xform_ret_ty
1672
1664
{
1665
+ // `xform_ret_ty` has only been normalized for `InherentImplCandidate`.
1666
+ // We don't normalize the other candidates for perf/backwards-compat reasons...
1667
+ // but `self.return_type` is only set on the diagnostic-path, so we
1668
+ // should be okay doing it here.
1669
+ if !matches ! ( probe. kind, InherentImplCandidate ( ..) ) {
1670
+ let InferOk {
1671
+ value : normalized_xform_ret_ty,
1672
+ obligations : normalization_obligations,
1673
+ } = self . fcx . at ( & cause, self . param_env ) . normalize ( xform_ret_ty) ;
1674
+ xform_ret_ty = normalized_xform_ret_ty;
1675
+ debug ! ( "xform_ret_ty after normalization: {:?}" , xform_ret_ty) ;
1676
+ // Evaluate those obligations to see if they might possibly hold.
1677
+ for o in normalization_obligations {
1678
+ let o = self . resolve_vars_if_possible ( o) ;
1679
+ if !self . predicate_may_hold ( & o) {
1680
+ result = ProbeResult :: NoMatch ;
1681
+ possibly_unsatisfied_predicates. push ( (
1682
+ o. predicate ,
1683
+ None ,
1684
+ Some ( o. cause ) ,
1685
+ ) ) ;
1686
+ }
1687
+ }
1688
+ }
1689
+
1673
1690
debug ! (
1674
1691
"comparing return_ty {:?} with xform ret ty {:?}" ,
1675
1692
return_ty, xform_ret_ty
@@ -1681,7 +1698,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1681
1698
. sup ( return_ty, xform_ret_ty)
1682
1699
. is_err ( )
1683
1700
{
1684
- return ProbeResult :: BadReturnType ;
1701
+ result = ProbeResult :: BadReturnType ;
1685
1702
}
1686
1703
}
1687
1704
0 commit comments