@@ -1521,11 +1521,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1521
1521
} ;
1522
1522
1523
1523
let mut result = ProbeResult :: Match ;
1524
- let mut xform_ret_ty = probe. xform_ret_ty ;
1525
- debug ! ( ?xform_ret_ty) ;
1526
-
1527
1524
let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
1528
1525
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
+
1529
1548
let mut parent_pred = None ;
1530
1549
1531
1550
// If so, impls may carry other conditions (e.g., where
@@ -1534,16 +1553,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1534
1553
// don't have enough information to fully evaluate).
1535
1554
match probe. kind {
1536
1555
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
-
1547
1556
// Check whether the impl imposes obligations we have to worry about.
1548
1557
let impl_def_id = probe. item . container_id ( self . tcx ) ;
1549
1558
let impl_bounds = self . tcx . predicates_of ( impl_def_id) ;
@@ -1554,15 +1563,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1554
1563
1555
1564
// Convert the bounds into obligations.
1556
1565
let impl_obligations = traits:: predicates_for_generics (
1557
- move |_, _| cause. clone ( ) ,
1566
+ |_, _| cause. clone ( ) ,
1558
1567
self . param_env ,
1559
1568
impl_bounds,
1560
1569
) ;
1561
1570
1562
1571
let candidate_obligations = impl_obligations
1563
1572
. chain ( norm_obligations. into_iter ( ) )
1564
- . chain ( ref_obligations. iter ( ) . cloned ( ) )
1565
- . chain ( normalization_obligations. into_iter ( ) ) ;
1573
+ . chain ( ref_obligations. iter ( ) . cloned ( ) ) ;
1566
1574
1567
1575
// Evaluate those obligations to see if they might possibly hold.
1568
1576
for o in candidate_obligations {
@@ -1597,7 +1605,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1597
1605
ty:: Binder :: dummy ( trait_ref) . without_const ( ) . to_predicate ( self . tcx ) ;
1598
1606
parent_pred = Some ( predicate) ;
1599
1607
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) ;
1601
1609
if !self . predicate_may_hold ( & obligation) {
1602
1610
result = ProbeResult :: NoMatch ;
1603
1611
if self . probe ( |_| {
@@ -1656,21 +1664,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1656
1664
}
1657
1665
}
1658
1666
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 ;
1674
1683
}
1675
1684
}
1676
1685
0 commit comments