@@ -29,7 +29,7 @@ use super::{
2929
3030use crate :: dep_graph:: { DepKind , DepNodeIndex } ;
3131use crate :: hir:: def_id:: DefId ;
32- use crate :: infer:: { InferCtxt , InferOk , TypeFreshener } ;
32+ use crate :: infer:: { CombinedSnapshot , InferCtxt , InferOk , PlaceholderMap , TypeFreshener } ;
3333use crate :: middle:: lang_items;
3434use crate :: mir:: interpret:: GlobalId ;
3535use crate :: ty:: fast_reject;
@@ -1667,8 +1667,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16671667 _ => return ,
16681668 }
16691669
1670- let result = self . infcx . probe ( |_| {
1671- self . match_projection_obligation_against_definition_bounds ( obligation)
1670+ let result = self . infcx . probe ( |snapshot| {
1671+ self . match_projection_obligation_against_definition_bounds (
1672+ obligation,
1673+ snapshot,
1674+ )
16721675 } ) ;
16731676
16741677 if result {
@@ -1679,10 +1682,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16791682 fn match_projection_obligation_against_definition_bounds (
16801683 & mut self ,
16811684 obligation : & TraitObligation < ' tcx > ,
1685+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
16821686 ) -> bool {
16831687 let poly_trait_predicate = self . infcx ( )
16841688 . resolve_type_vars_if_possible ( & obligation. predicate ) ;
1685- let ( placeholder_trait_predicate, _ ) = self . infcx ( )
1689+ let ( placeholder_trait_predicate, placeholder_map ) = self . infcx ( )
16861690 . replace_bound_vars_with_placeholders ( & poly_trait_predicate) ;
16871691 debug ! (
16881692 "match_projection_obligation_against_definition_bounds: \
@@ -1724,6 +1728,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17241728 obligation,
17251729 bound. clone ( ) ,
17261730 placeholder_trait_predicate. trait_ref . clone ( ) ,
1731+ & placeholder_map,
1732+ snapshot,
17271733 )
17281734 } )
17291735 } ) ;
@@ -1741,6 +1747,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17411747 obligation,
17421748 bound,
17431749 placeholder_trait_predicate. trait_ref . clone ( ) ,
1750+ & placeholder_map,
1751+ snapshot,
17441752 ) ;
17451753
17461754 assert ! ( result) ;
@@ -1754,12 +1762,16 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17541762 obligation : & TraitObligation < ' tcx > ,
17551763 trait_bound : ty:: PolyTraitRef < ' tcx > ,
17561764 placeholder_trait_ref : ty:: TraitRef < ' tcx > ,
1765+ placeholder_map : & PlaceholderMap < ' tcx > ,
1766+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
17571767 ) -> bool {
17581768 debug_assert ! ( !placeholder_trait_ref. has_escaping_bound_vars( ) ) ;
17591769 self . infcx
17601770 . at ( & obligation. cause , obligation. param_env )
17611771 . sup ( ty:: Binder :: dummy ( placeholder_trait_ref) , trait_bound)
17621772 . is_ok ( )
1773+ &&
1774+ self . infcx . leak_check ( false , placeholder_map, snapshot) . is_ok ( )
17631775 }
17641776
17651777 /// Given an obligation like `<SomeTrait for T>`, search the obligations that the caller
@@ -1960,8 +1972,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19601972 obligation. predicate . def_id ( ) ,
19611973 obligation. predicate . skip_binder ( ) . trait_ref . self_ty ( ) ,
19621974 |impl_def_id| {
1963- self . infcx . probe ( |_ | {
1964- if let Ok ( _substs) = self . match_impl ( impl_def_id, obligation)
1975+ self . infcx . probe ( |snapshot | {
1976+ if let Ok ( _substs) = self . match_impl ( impl_def_id, obligation, snapshot )
19651977 {
19661978 candidates. vec . push ( ImplCandidate ( impl_def_id) ) ;
19671979 }
@@ -2758,9 +2770,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27582770 }
27592771
27602772 fn confirm_projection_candidate ( & mut self , obligation : & TraitObligation < ' tcx > ) {
2761- self . infcx . in_snapshot ( |_ | {
2773+ self . infcx . in_snapshot ( |snapshot | {
27622774 let result =
2763- self . match_projection_obligation_against_definition_bounds ( obligation) ;
2775+ self . match_projection_obligation_against_definition_bounds (
2776+ obligation,
2777+ snapshot,
2778+ ) ;
27642779 assert ! ( result) ;
27652780 } )
27662781 }
@@ -2912,8 +2927,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29122927
29132928 // First, create the substitutions by matching the impl again,
29142929 // this time not in a probe.
2915- self . infcx . in_snapshot ( |_ | {
2916- let substs = self . rematch_impl ( impl_def_id, obligation) ;
2930+ self . infcx . in_snapshot ( |snapshot | {
2931+ let substs = self . rematch_impl ( impl_def_id, obligation, snapshot ) ;
29172932 debug ! ( "confirm_impl_candidate: substs={:?}" , substs) ;
29182933 let cause = obligation. derived_cause ( ImplDerivedObligation ) ;
29192934 self . vtable_impl (
@@ -3504,8 +3519,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35043519 & mut self ,
35053520 impl_def_id : DefId ,
35063521 obligation : & TraitObligation < ' tcx > ,
3522+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
35073523 ) -> Normalized < ' tcx , & ' tcx Substs < ' tcx > > {
3508- match self . match_impl ( impl_def_id, obligation) {
3524+ match self . match_impl ( impl_def_id, obligation, snapshot ) {
35093525 Ok ( substs) => substs,
35103526 Err ( ( ) ) => {
35113527 bug ! (
@@ -3521,6 +3537,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35213537 & mut self ,
35223538 impl_def_id : DefId ,
35233539 obligation : & TraitObligation < ' tcx > ,
3540+ snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
35243541 ) -> Result < Normalized < ' tcx , & ' tcx Substs < ' tcx > > , ( ) > {
35253542 let impl_trait_ref = self . tcx ( ) . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
35263543
@@ -3531,7 +3548,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35313548 return Err ( ( ) ) ;
35323549 }
35333550
3534- let ( skol_obligation, _ ) = self . infcx ( )
3551+ let ( skol_obligation, placeholder_map ) = self . infcx ( )
35353552 . replace_bound_vars_with_placeholders ( & obligation. predicate ) ;
35363553 let skol_obligation_trait_ref = skol_obligation. trait_ref ;
35373554
@@ -3563,6 +3580,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35633580 . map_err ( |e| debug ! ( "match_impl: failed eq_trait_refs due to `{}`" , e) ) ?;
35643581 nested_obligations. extend ( obligations) ;
35653582
3583+ if let Err ( e) = self . infcx . leak_check ( false , & placeholder_map, snapshot) {
3584+ debug ! ( "match_impl: failed leak check due to `{}`" , e) ;
3585+ return Err ( ( ) ) ;
3586+ }
3587+
35663588 debug ! ( "match_impl: success impl_substs={:?}" , impl_substs) ;
35673589 Ok ( Normalized {
35683590 value : impl_substs,
0 commit comments