@@ -134,7 +134,6 @@ use std::collections::hash_map::Entry;
134134use std:: cmp;
135135use std:: fmt:: Display ;
136136use std:: iter;
137- use std:: vec;
138137use std:: mem:: replace;
139138use std:: ops:: { self , Deref } ;
140139use std:: slice;
@@ -143,6 +142,7 @@ use require_c_abi_if_variadic;
143142use session:: { CompileIncomplete , config, Session } ;
144143use TypeAndSubsts ;
145144use lint;
145+ use util:: captures:: Captures ;
146146use util:: common:: { ErrorReported , indenter} ;
147147use util:: nodemap:: { DefIdMap , DefIdSet , FxHashMap , FxHashSet , NodeMap } ;
148148
@@ -2751,55 +2751,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
27512751 _ => false
27522752 }
27532753 }
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- }
27692754
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 > {
28002755 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
28032757 {
28042758 let ty_var_root = self . root_var ( self_ty) ;
28052759 debug ! ( "obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}" ,
@@ -2810,12 +2764,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28102764 . borrow ( )
28112765 . pending_obligations ( )
28122766 . 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) )
28142786 }
28152787
28162788 fn type_var_is_sized ( & self , self_ty : ty:: TyVid ) -> bool {
28172789 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 ( )
28192791 } )
28202792 }
28212793
0 commit comments