@@ -29,7 +29,7 @@ use super::{
29
29
30
30
use dep_graph:: { DepKind , DepNodeIndex } ;
31
31
use hir:: def_id:: DefId ;
32
- use infer:: { InferCtxt , InferOk , TypeFreshener } ;
32
+ use infer:: { CombinedSnapshot , InferCtxt , InferOk , PlaceholderMap , TypeFreshener } ;
33
33
use middle:: lang_items;
34
34
use mir:: interpret:: GlobalId ;
35
35
use ty:: fast_reject;
@@ -1624,8 +1624,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1624
1624
_ => return ,
1625
1625
}
1626
1626
1627
- let result = self . infcx . probe ( |_| {
1628
- self . match_projection_obligation_against_definition_bounds ( obligation)
1627
+ let result = self . infcx . probe ( |snapshot| {
1628
+ self . match_projection_obligation_against_definition_bounds (
1629
+ obligation,
1630
+ snapshot,
1631
+ )
1629
1632
} ) ;
1630
1633
1631
1634
if result {
@@ -1636,10 +1639,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1636
1639
fn match_projection_obligation_against_definition_bounds (
1637
1640
& mut self ,
1638
1641
obligation : & TraitObligation < ' tcx > ,
1642
+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
1639
1643
) -> bool {
1640
1644
let poly_trait_predicate = self . infcx ( )
1641
1645
. resolve_type_vars_if_possible ( & obligation. predicate ) ;
1642
- let ( placeholder_trait_predicate, _ ) = self . infcx ( )
1646
+ let ( placeholder_trait_predicate, placeholder_map ) = self . infcx ( )
1643
1647
. replace_bound_vars_with_placeholders ( & poly_trait_predicate) ;
1644
1648
debug ! (
1645
1649
"match_projection_obligation_against_definition_bounds: \
@@ -1681,6 +1685,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1681
1685
obligation,
1682
1686
bound. clone ( ) ,
1683
1687
placeholder_trait_predicate. trait_ref . clone ( ) ,
1688
+ & placeholder_map,
1689
+ snapshot,
1684
1690
)
1685
1691
} )
1686
1692
} ) ;
@@ -1698,6 +1704,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1698
1704
obligation,
1699
1705
bound,
1700
1706
placeholder_trait_predicate. trait_ref . clone ( ) ,
1707
+ & placeholder_map,
1708
+ snapshot,
1701
1709
) ;
1702
1710
1703
1711
assert ! ( result) ;
@@ -1711,12 +1719,16 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1711
1719
obligation : & TraitObligation < ' tcx > ,
1712
1720
trait_bound : ty:: PolyTraitRef < ' tcx > ,
1713
1721
placeholder_trait_ref : ty:: TraitRef < ' tcx > ,
1722
+ placeholder_map : & PlaceholderMap < ' tcx > ,
1723
+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
1714
1724
) -> bool {
1715
1725
debug_assert ! ( !placeholder_trait_ref. has_escaping_bound_vars( ) ) ;
1716
1726
self . infcx
1717
1727
. at ( & obligation. cause , obligation. param_env )
1718
1728
. sup ( ty:: Binder :: dummy ( placeholder_trait_ref) , trait_bound)
1719
1729
. is_ok ( )
1730
+ &&
1731
+ self . infcx . leak_check ( false , placeholder_map, snapshot) . is_ok ( )
1720
1732
}
1721
1733
1722
1734
/// Given an obligation like `<SomeTrait for T>`, search the obligations that the caller
@@ -1917,8 +1929,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1917
1929
obligation. predicate . def_id ( ) ,
1918
1930
obligation. predicate . skip_binder ( ) . trait_ref . self_ty ( ) ,
1919
1931
|impl_def_id| {
1920
- self . infcx . probe ( |_ | {
1921
- if let Ok ( _substs) = self . match_impl ( impl_def_id, obligation)
1932
+ self . infcx . probe ( |snapshot | {
1933
+ if let Ok ( _substs) = self . match_impl ( impl_def_id, obligation, snapshot )
1922
1934
{
1923
1935
candidates. vec . push ( ImplCandidate ( impl_def_id) ) ;
1924
1936
}
@@ -2697,9 +2709,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2697
2709
}
2698
2710
2699
2711
fn confirm_projection_candidate ( & mut self , obligation : & TraitObligation < ' tcx > ) {
2700
- self . infcx . in_snapshot ( |_ | {
2712
+ self . infcx . in_snapshot ( |snapshot | {
2701
2713
let result =
2702
- self . match_projection_obligation_against_definition_bounds ( obligation) ;
2714
+ self . match_projection_obligation_against_definition_bounds (
2715
+ obligation,
2716
+ snapshot,
2717
+ ) ;
2703
2718
assert ! ( result) ;
2704
2719
} )
2705
2720
}
@@ -2851,8 +2866,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2851
2866
2852
2867
// First, create the substitutions by matching the impl again,
2853
2868
// this time not in a probe.
2854
- self . infcx . in_snapshot ( |_ | {
2855
- let substs = self . rematch_impl ( impl_def_id, obligation) ;
2869
+ self . infcx . in_snapshot ( |snapshot | {
2870
+ let substs = self . rematch_impl ( impl_def_id, obligation, snapshot ) ;
2856
2871
debug ! ( "confirm_impl_candidate: substs={:?}" , substs) ;
2857
2872
let cause = obligation. derived_cause ( ImplDerivedObligation ) ;
2858
2873
self . vtable_impl (
@@ -3443,8 +3458,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3443
3458
& mut self ,
3444
3459
impl_def_id : DefId ,
3445
3460
obligation : & TraitObligation < ' tcx > ,
3461
+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
3446
3462
) -> Normalized < ' tcx , & ' tcx Substs < ' tcx > > {
3447
- match self . match_impl ( impl_def_id, obligation) {
3463
+ match self . match_impl ( impl_def_id, obligation, snapshot ) {
3448
3464
Ok ( substs) => substs,
3449
3465
Err ( ( ) ) => {
3450
3466
bug ! (
@@ -3460,6 +3476,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3460
3476
& mut self ,
3461
3477
impl_def_id : DefId ,
3462
3478
obligation : & TraitObligation < ' tcx > ,
3479
+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
3463
3480
) -> Result < Normalized < ' tcx , & ' tcx Substs < ' tcx > > , ( ) > {
3464
3481
let impl_trait_ref = self . tcx ( ) . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
3465
3482
@@ -3470,7 +3487,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3470
3487
return Err ( ( ) ) ;
3471
3488
}
3472
3489
3473
- let ( skol_obligation, _ ) = self . infcx ( )
3490
+ let ( skol_obligation, placeholder_map ) = self . infcx ( )
3474
3491
. replace_bound_vars_with_placeholders ( & obligation. predicate ) ;
3475
3492
let skol_obligation_trait_ref = skol_obligation. trait_ref ;
3476
3493
@@ -3502,6 +3519,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3502
3519
. map_err ( |e| debug ! ( "match_impl: failed eq_trait_refs due to `{}`" , e) ) ?;
3503
3520
nested_obligations. extend ( obligations) ;
3504
3521
3522
+ if let Err ( e) = self . infcx . leak_check ( false , & placeholder_map, snapshot) {
3523
+ debug ! ( "match_impl: failed leak check due to `{}`" , e) ;
3524
+ return Err ( ( ) ) ;
3525
+ }
3526
+
3505
3527
debug ! ( "match_impl: success impl_substs={:?}" , impl_substs) ;
3506
3528
Ok ( Normalized {
3507
3529
value : impl_substs,
0 commit comments