@@ -29,8 +29,7 @@ use super::{
29
29
30
30
use dep_graph:: { DepKind , DepNodeIndex } ;
31
31
use hir:: def_id:: DefId ;
32
- use infer;
33
- use infer:: { InferCtxt , InferOk , TypeFreshener } ;
32
+ use infer:: { self , InferCtxt , InferOk , TypeFreshener } ;
34
33
use middle:: lang_items;
35
34
use mir:: interpret:: GlobalId ;
36
35
use ty:: fast_reject;
@@ -531,24 +530,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
531
530
self . infcx
532
531
}
533
532
534
- /// Wraps the inference context's in_snapshot s.t. snapshot handling is only from the selection
535
- /// context's self.
536
- fn in_snapshot < R , F > ( & mut self , f : F ) -> R
537
- where
538
- F : FnOnce ( & mut Self , & infer:: CombinedSnapshot < ' cx , ' tcx > ) -> R ,
539
- {
540
- self . infcx . in_snapshot ( |snapshot| f ( self , snapshot) )
541
- }
542
-
543
- /// Wraps a probe s.t. obligations collected during it are ignored and old obligations are
544
- /// retained.
545
- fn probe < R , F > ( & mut self , f : F ) -> R
546
- where
547
- F : FnOnce ( & mut Self , & infer:: CombinedSnapshot < ' cx , ' tcx > ) -> R ,
548
- {
549
- self . infcx . probe ( |snapshot| f ( self , snapshot) )
550
- }
551
-
552
533
///////////////////////////////////////////////////////////////////////////
553
534
// Selection
554
535
//
@@ -630,8 +611,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
630
611
& mut self ,
631
612
obligation : & PredicateObligation < ' tcx > ,
632
613
) -> Result < EvaluationResult , OverflowError > {
633
- self . probe ( |this , _| {
634
- this . evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
614
+ self . infcx . probe ( |_| {
615
+ self . evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
635
616
} )
636
617
}
637
618
@@ -1066,10 +1047,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1066
1047
"evaluate_candidate: depth={} candidate={:?}" ,
1067
1048
stack. obligation. recursion_depth, candidate
1068
1049
) ;
1069
- let result = self . probe ( |this , _| {
1050
+ let result = self . infcx . probe ( |_| {
1070
1051
let candidate = ( * candidate) . clone ( ) ;
1071
- match this . confirm_candidate ( stack. obligation , candidate) {
1072
- Ok ( selection) => this . evaluate_predicates_recursively (
1052
+ match self . confirm_candidate ( stack. obligation , candidate) {
1053
+ Ok ( selection) => self . evaluate_predicates_recursively (
1073
1054
stack. list ( ) ,
1074
1055
selection. nested_obligations ( ) . iter ( ) ,
1075
1056
) ,
@@ -1697,8 +1678,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1697
1678
_ => return ,
1698
1679
}
1699
1680
1700
- let result = self . probe ( |this , snapshot| {
1701
- this . match_projection_obligation_against_definition_bounds ( obligation, snapshot)
1681
+ let result = self . infcx . probe ( |snapshot| {
1682
+ self . match_projection_obligation_against_definition_bounds ( obligation, snapshot)
1702
1683
} ) ;
1703
1684
1704
1685
if result {
@@ -1750,8 +1731,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1750
1731
let matching_bound = util:: elaborate_predicates ( self . tcx ( ) , bounds. predicates )
1751
1732
. filter_to_traits ( )
1752
1733
. find ( |bound| {
1753
- self . probe ( |this , _| {
1754
- this . match_projection (
1734
+ self . infcx . probe ( |_| {
1735
+ self . match_projection (
1755
1736
obligation,
1756
1737
bound. clone ( ) ,
1757
1738
skol_trait_predicate. trait_ref . clone ( ) ,
@@ -1853,10 +1834,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1853
1834
stack : & TraitObligationStack < ' o , ' tcx > ,
1854
1835
where_clause_trait_ref : ty:: PolyTraitRef < ' tcx > ,
1855
1836
) -> Result < EvaluationResult , OverflowError > {
1856
- self . probe ( move |this , _| {
1857
- match this . match_where_clause_trait_ref ( stack. obligation , where_clause_trait_ref) {
1837
+ self . infcx . probe ( | _| {
1838
+ match self . match_where_clause_trait_ref ( stack. obligation , where_clause_trait_ref) {
1858
1839
Ok ( obligations) => {
1859
- this . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
1840
+ self . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
1860
1841
}
1861
1842
Err ( ( ) ) => Ok ( EvaluatedToErr ) ,
1862
1843
}
@@ -2006,8 +1987,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2006
1987
obligation. predicate . def_id ( ) ,
2007
1988
obligation. predicate . skip_binder ( ) . trait_ref . self_ty ( ) ,
2008
1989
|impl_def_id| {
2009
- self . probe ( |this , snapshot| {
2010
- if let Ok ( placeholder_map) = this . match_impl ( impl_def_id, obligation, snapshot)
1990
+ self . infcx . probe ( |snapshot| {
1991
+ if let Ok ( placeholder_map) = self . match_impl ( impl_def_id, obligation, snapshot)
2011
1992
{
2012
1993
candidates. vec . push ( ImplCandidate ( impl_def_id) ) ;
2013
1994
@@ -2084,11 +2065,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2084
2065
obligation. self_ty( ) . skip_binder( )
2085
2066
) ;
2086
2067
2087
- self . probe ( |this , _snapshot| {
2068
+ self . infcx . probe ( |_snapshot| {
2088
2069
// The code below doesn't care about regions, and the
2089
2070
// self-ty here doesn't escape this probe, so just erase
2090
2071
// any LBR.
2091
- let self_ty = this . tcx ( ) . erase_late_bound_regions ( & obligation. self_ty ( ) ) ;
2072
+ let self_ty = self . tcx ( ) . erase_late_bound_regions ( & obligation. self_ty ( ) ) ;
2092
2073
let poly_trait_ref = match self_ty. sty {
2093
2074
ty:: Dynamic ( ref data, ..) => {
2094
2075
if data. auto_traits ( )
@@ -2102,7 +2083,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2102
2083
return ;
2103
2084
}
2104
2085
2105
- data. principal ( ) . with_self_ty ( this . tcx ( ) , self_ty)
2086
+ data. principal ( ) . with_self_ty ( self . tcx ( ) , self_ty)
2106
2087
}
2107
2088
ty:: Infer ( ty:: TyVar ( _) ) => {
2108
2089
debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
@@ -2122,11 +2103,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2122
2103
// correct trait, but also the correct type parameters.
2123
2104
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
2124
2105
// but `Foo` is declared as `trait Foo : Bar<u32>`.
2125
- let upcast_trait_refs = util:: supertraits ( this . tcx ( ) , poly_trait_ref)
2106
+ let upcast_trait_refs = util:: supertraits ( self . tcx ( ) , poly_trait_ref)
2126
2107
. filter ( |upcast_trait_ref| {
2127
- this . probe ( |this , _| {
2108
+ self . infcx . probe ( |_| {
2128
2109
let upcast_trait_ref = upcast_trait_ref. clone ( ) ;
2129
- this . match_poly_trait_ref ( obligation, upcast_trait_ref)
2110
+ self . match_poly_trait_ref ( obligation, upcast_trait_ref)
2130
2111
. is_ok ( )
2131
2112
} )
2132
2113
} )
@@ -2671,20 +2652,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2671
2652
// binder moved -\
2672
2653
let ty: ty:: Binder < Ty < ' tcx > > = ty:: Binder :: bind ( ty) ; // <----/
2673
2654
2674
- self . in_snapshot ( |this , snapshot| {
2675
- let ( skol_ty, placeholder_map) = this . infcx ( )
2655
+ self . infcx . in_snapshot ( |snapshot| {
2656
+ let ( skol_ty, placeholder_map) = self . infcx
2676
2657
. replace_bound_vars_with_placeholders ( & ty) ;
2677
2658
let Normalized {
2678
2659
value : normalized_ty,
2679
2660
mut obligations,
2680
2661
} = project:: normalize_with_depth (
2681
- this ,
2662
+ self ,
2682
2663
param_env,
2683
2664
cause. clone ( ) ,
2684
2665
recursion_depth,
2685
2666
& skol_ty,
2686
2667
) ;
2687
- let skol_obligation = this . tcx ( ) . predicate_for_trait_def (
2668
+ let skol_obligation = self . tcx ( ) . predicate_for_trait_def (
2688
2669
param_env,
2689
2670
cause. clone ( ) ,
2690
2671
trait_def_id,
@@ -2693,7 +2674,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2693
2674
& [ ] ,
2694
2675
) ;
2695
2676
obligations. push ( skol_obligation) ;
2696
- this . infcx ( )
2677
+ self . infcx
2697
2678
. plug_leaks ( placeholder_map, snapshot, obligations)
2698
2679
} )
2699
2680
} )
@@ -2785,9 +2766,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2785
2766
}
2786
2767
2787
2768
fn confirm_projection_candidate ( & mut self , obligation : & TraitObligation < ' tcx > ) {
2788
- self . in_snapshot ( |this , snapshot| {
2769
+ self . infcx . in_snapshot ( |snapshot| {
2789
2770
let result =
2790
- this . match_projection_obligation_against_definition_bounds ( obligation, snapshot) ;
2771
+ self . match_projection_obligation_against_definition_bounds ( obligation, snapshot) ;
2791
2772
assert ! ( result) ;
2792
2773
} )
2793
2774
}
@@ -2904,12 +2885,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2904
2885
nested,
2905
2886
) ;
2906
2887
2907
- let trait_obligations: Vec < PredicateObligation < ' _ > > = self . in_snapshot ( |this , snapshot| {
2888
+ let trait_obligations: Vec < PredicateObligation < ' _ > > = self . infcx . in_snapshot ( |snapshot| {
2908
2889
let poly_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
2909
- let ( trait_ref, placeholder_map) = this . infcx ( )
2890
+ let ( trait_ref, placeholder_map) = self . infcx
2910
2891
. replace_bound_vars_with_placeholders ( & poly_trait_ref) ;
2911
2892
let cause = obligation. derived_cause ( ImplDerivedObligation ) ;
2912
- this . impl_or_trait_obligations (
2893
+ self . impl_or_trait_obligations (
2913
2894
cause,
2914
2895
obligation. recursion_depth + 1 ,
2915
2896
obligation. param_env ,
@@ -2941,11 +2922,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2941
2922
2942
2923
// First, create the substitutions by matching the impl again,
2943
2924
// this time not in a probe.
2944
- self . in_snapshot ( |this , snapshot| {
2945
- let ( substs, placeholder_map) = this . rematch_impl ( impl_def_id, obligation, snapshot) ;
2925
+ self . infcx . in_snapshot ( |snapshot| {
2926
+ let ( substs, placeholder_map) = self . rematch_impl ( impl_def_id, obligation, snapshot) ;
2946
2927
debug ! ( "confirm_impl_candidate: substs={:?}" , substs) ;
2947
2928
let cause = obligation. derived_cause ( ImplDerivedObligation ) ;
2948
- this . vtable_impl (
2929
+ self . vtable_impl (
2949
2930
impl_def_id,
2950
2931
substs,
2951
2932
cause,
@@ -3108,14 +3089,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3108
3089
obligation, alias_def_id
3109
3090
) ;
3110
3091
3111
- self . in_snapshot ( |this , snapshot| {
3112
- let ( predicate, placeholder_map) = this . infcx ( )
3092
+ self . infcx . in_snapshot ( |snapshot| {
3093
+ let ( predicate, placeholder_map) = self . infcx
3113
3094
. replace_bound_vars_with_placeholders ( & obligation. predicate ) ;
3114
3095
let trait_ref = predicate. trait_ref ;
3115
3096
let trait_def_id = trait_ref. def_id ;
3116
3097
let substs = trait_ref. substs ;
3117
3098
3118
- let trait_obligations = this . impl_or_trait_obligations (
3099
+ let trait_obligations = self . impl_or_trait_obligations (
3119
3100
obligation. cause . clone ( ) ,
3120
3101
obligation. recursion_depth ,
3121
3102
obligation. param_env ,
0 commit comments