@@ -753,17 +753,27 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
753
753
let ( impl_ty, impl_substs) = self . impl_ty_and_substs ( impl_def_id) ;
754
754
let impl_ty = impl_ty. subst ( self . tcx , impl_substs) ;
755
755
756
+ debug ! ( "impl_ty: {:?}" , impl_ty) ;
757
+
756
758
// Determine the receiver type that the method itself expects.
757
- let xform_tys = self . xform_self_ty ( & item, impl_ty, impl_substs) ;
759
+ let ( xform_self_ty, xform_ret_ty) = self . xform_self_ty ( & item, impl_ty, impl_substs) ;
760
+ debug ! ( "xform_self_ty: {:?}, xform_ret_ty: {:?}" , xform_self_ty, xform_ret_ty) ;
758
761
759
762
// We can't use normalize_associated_types_in as it will pollute the
760
763
// fcx's fulfillment context after this probe is over.
764
+ // Note: we only normalize `xform_self_ty` here since the normalization
765
+ // of the return type can lead to inference results that prohibit
766
+ // valid canidates from being found, see issue #85671
767
+ // FIXME Postponing the normalization of the return type likely only hides a deeper bug,
768
+ // which might be caused by the `param_env` itself. The clauses of the `param_env`
769
+ // maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
770
+ // see isssue #89650
761
771
let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
762
772
let selcx = & mut traits:: SelectionContext :: new ( self . fcx ) ;
763
- let traits:: Normalized { value : ( xform_self_ty, xform_ret_ty ) , obligations } =
764
- traits:: normalize ( selcx, self . param_env , cause, xform_tys ) ;
773
+ let traits:: Normalized { value : xform_self_ty, obligations } =
774
+ traits:: normalize ( selcx, self . param_env , cause, xform_self_ty ) ;
765
775
debug ! (
766
- "assemble_inherent_impl_probe: xform_self_ty = {:?}/{:?}" ,
776
+ "assemble_inherent_impl_probe after normalization : xform_self_ty = {:?}/{:?}" ,
767
777
xform_self_ty, xform_ret_ty
768
778
) ;
769
779
@@ -1420,6 +1430,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1420
1430
} ;
1421
1431
1422
1432
let mut result = ProbeResult :: Match ;
1433
+ let mut xform_ret_ty = probe. xform_ret_ty ;
1434
+ debug ! ( ?xform_ret_ty) ;
1435
+
1423
1436
let selcx = & mut traits:: SelectionContext :: new ( self ) ;
1424
1437
let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
1425
1438
@@ -1428,7 +1441,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1428
1441
// match as well (or at least may match, sometimes we
1429
1442
// don't have enough information to fully evaluate).
1430
1443
match probe. kind {
1431
- InherentImplCandidate ( substs, ref ref_obligations) => {
1444
+ InherentImplCandidate ( ref substs, ref ref_obligations) => {
1445
+ // `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1446
+ // see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1447
+ // for why this is necessary
1448
+ let traits:: Normalized {
1449
+ value : normalized_xform_ret_ty,
1450
+ obligations : normalization_obligations,
1451
+ } = traits:: normalize ( selcx, self . param_env , cause. clone ( ) , probe. xform_ret_ty ) ;
1452
+ xform_ret_ty = normalized_xform_ret_ty;
1453
+ debug ! ( "xform_ret_ty after normalization: {:?}" , xform_ret_ty) ;
1454
+
1432
1455
// Check whether the impl imposes obligations we have to worry about.
1433
1456
let impl_def_id = probe. item . container . id ( ) ;
1434
1457
let impl_bounds = self . tcx . predicates_of ( impl_def_id) ;
@@ -1442,7 +1465,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1442
1465
1443
1466
let candidate_obligations = impl_obligations
1444
1467
. chain ( norm_obligations. into_iter ( ) )
1445
- . chain ( ref_obligations. iter ( ) . cloned ( ) ) ;
1468
+ . chain ( ref_obligations. iter ( ) . cloned ( ) )
1469
+ . chain ( normalization_obligations. into_iter ( ) ) ;
1470
+
1446
1471
// Evaluate those obligations to see if they might possibly hold.
1447
1472
for o in candidate_obligations {
1448
1473
let o = self . resolve_vars_if_possible ( o) ;
@@ -1527,9 +1552,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1527
1552
}
1528
1553
1529
1554
if let ProbeResult :: Match = result {
1530
- if let ( Some ( return_ty) , Some ( xform_ret_ty) ) =
1531
- ( self . return_type , probe. xform_ret_ty )
1532
- {
1555
+ if let ( Some ( return_ty) , Some ( xform_ret_ty) ) = ( self . return_type , xform_ret_ty) {
1533
1556
let xform_ret_ty = self . resolve_vars_if_possible ( xform_ret_ty) ;
1534
1557
debug ! (
1535
1558
"comparing return_ty {:?} with xform ret ty {:?}" ,
@@ -1669,6 +1692,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1669
1692
self . static_candidates . push ( source) ;
1670
1693
}
1671
1694
1695
+ #[ instrument( level = "debug" , skip( self ) ) ]
1672
1696
fn xform_self_ty (
1673
1697
& self ,
1674
1698
item : & ty:: AssocItem ,
@@ -1683,9 +1707,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1683
1707
}
1684
1708
}
1685
1709
1710
+ #[ instrument( level = "debug" , skip( self ) ) ]
1686
1711
fn xform_method_sig ( & self , method : DefId , substs : SubstsRef < ' tcx > ) -> ty:: FnSig < ' tcx > {
1687
1712
let fn_sig = self . tcx . fn_sig ( method) ;
1688
- debug ! ( "xform_self_ty(fn_sig={:?}, substs={:?})" , fn_sig, substs ) ;
1713
+ debug ! ( ? fn_sig) ;
1689
1714
1690
1715
assert ! ( !substs. has_escaping_bound_vars( ) ) ;
1691
1716
0 commit comments