@@ -134,7 +134,6 @@ use std::collections::hash_map::Entry;
134
134
use std:: cmp;
135
135
use std:: fmt:: Display ;
136
136
use std:: iter;
137
- use std:: vec;
138
137
use std:: mem:: replace;
139
138
use std:: ops:: { self , Deref } ;
140
139
use std:: slice;
@@ -143,6 +142,7 @@ use require_c_abi_if_variadic;
143
142
use session:: { CompileIncomplete , config, Session } ;
144
143
use TypeAndSubsts ;
145
144
use lint;
145
+ use util:: captures:: Captures ;
146
146
use util:: common:: { ErrorReported , indenter} ;
147
147
use util:: nodemap:: { DefIdMap , DefIdSet , FxHashMap , FxHashSet , NodeMap } ;
148
148
@@ -2751,55 +2751,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2751
2751
_ => false
2752
2752
}
2753
2753
}
2754
- }
2755
-
2756
- /// FIXME: impl Trait why u give me lifetime errors?
2757
- pub struct ObligationMapper < ' a , ' gcx , ' tcx > ( & ' a FnCtxt < ' a , ' gcx , ' tcx > , ty:: TyVid ) ;
2758
-
2759
- impl < ' a , ' gcx , ' tcx > FnOnce < ( traits:: PredicateObligation < ' tcx > , ) >
2760
- for ObligationMapper < ' a , ' gcx , ' tcx >
2761
- {
2762
- type Output = Option < ty:: PolyTraitRef < ' tcx > > ;
2763
-
2764
- extern "rust-call" fn call_once ( mut self , args : ( traits:: PredicateObligation < ' tcx > , ) )
2765
- -> Self :: Output {
2766
- self . call_mut ( args)
2767
- }
2768
- }
2769
2754
2770
- impl < ' a , ' gcx , ' tcx > FnMut < ( traits:: PredicateObligation < ' tcx > , ) >
2771
- for ObligationMapper < ' a , ' gcx , ' tcx >
2772
- {
2773
- extern "rust-call" fn call_mut ( & mut self , args : ( traits:: PredicateObligation < ' tcx > , ) )
2774
- -> Self :: Output {
2775
- match args. 0 . predicate {
2776
- ty:: Predicate :: Projection ( ref data) => Some ( data. to_poly_trait_ref ( self . 0 . tcx ) ) ,
2777
- ty:: Predicate :: Trait ( ref data) => Some ( data. to_poly_trait_ref ( ) ) ,
2778
- ty:: Predicate :: Subtype ( ..) => None ,
2779
- ty:: Predicate :: RegionOutlives ( ..) => None ,
2780
- ty:: Predicate :: TypeOutlives ( ..) => None ,
2781
- ty:: Predicate :: WellFormed ( ..) => None ,
2782
- ty:: Predicate :: ObjectSafe ( ..) => None ,
2783
- ty:: Predicate :: ConstEvaluatable ( ..) => None ,
2784
- // N.B., this predicate is created by breaking down a
2785
- // `ClosureType: FnFoo()` predicate, where
2786
- // `ClosureType` represents some `Closure`. It can't
2787
- // possibly be referring to the current closure,
2788
- // because we haven't produced the `Closure` for
2789
- // this closure yet; this is exactly why the other
2790
- // code is looking for a self type of a unresolved
2791
- // inference variable.
2792
- ty:: Predicate :: ClosureKind ( ..) => None ,
2793
- } . filter ( |tr| {
2794
- self . 0 . self_type_matches_expected_vid ( * tr, self . 1 )
2795
- } )
2796
- }
2797
- }
2798
-
2799
- impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
2800
2755
fn obligations_for_self_ty < ' b > ( & ' b self , self_ty : ty:: TyVid )
2801
- -> iter:: FilterMap < vec:: IntoIter < traits:: PredicateObligation < ' tcx > > ,
2802
- ObligationMapper < ' b , ' gcx , ' tcx > >
2756
+ -> impl Iterator < Item =ty:: PolyTraitRef < ' tcx > > + Captures < ' gcx > + ' b
2803
2757
{
2804
2758
let ty_var_root = self . root_var ( self_ty) ;
2805
2759
debug ! ( "obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}" ,
@@ -2810,12 +2764,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2810
2764
. borrow ( )
2811
2765
. pending_obligations ( )
2812
2766
. into_iter ( )
2813
- . filter_map ( ObligationMapper ( self , ty_var_root) )
2767
+ . filter_map ( move |obligation| match obligation. predicate {
2768
+ ty:: Predicate :: Projection ( ref data) => Some ( data. to_poly_trait_ref ( self . tcx ) ) ,
2769
+ ty:: Predicate :: Trait ( ref data) => Some ( data. to_poly_trait_ref ( ) ) ,
2770
+ ty:: Predicate :: Subtype ( ..) => None ,
2771
+ ty:: Predicate :: RegionOutlives ( ..) => None ,
2772
+ ty:: Predicate :: TypeOutlives ( ..) => None ,
2773
+ ty:: Predicate :: WellFormed ( ..) => None ,
2774
+ ty:: Predicate :: ObjectSafe ( ..) => None ,
2775
+ ty:: Predicate :: ConstEvaluatable ( ..) => None ,
2776
+ // N.B., this predicate is created by breaking down a
2777
+ // `ClosureType: FnFoo()` predicate, where
2778
+ // `ClosureType` represents some `Closure`. It can't
2779
+ // possibly be referring to the current closure,
2780
+ // because we haven't produced the `Closure` for
2781
+ // this closure yet; this is exactly why the other
2782
+ // code is looking for a self type of a unresolved
2783
+ // inference variable.
2784
+ ty:: Predicate :: ClosureKind ( ..) => None ,
2785
+ } ) . filter ( move |tr| self . self_type_matches_expected_vid ( * tr, ty_var_root) )
2814
2786
}
2815
2787
2816
2788
fn type_var_is_sized ( & self , self_ty : ty:: TyVid ) -> bool {
2817
2789
self . obligations_for_self_ty ( self_ty) . any ( |tr| {
2818
- Some ( tr. def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( )
2790
+ Some ( tr. def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( )
2819
2791
} )
2820
2792
}
2821
2793
0 commit comments