@@ -114,8 +114,8 @@ use rustc::mir::interpret::{ConstValue, GlobalId};
114114use rustc:: ty:: subst:: { CanonicalUserSubsts , UnpackedKind , Subst , Substs ,
115115 UserSelfTy , UserSubsts } ;
116116use rustc:: traits:: { self , ObligationCause , ObligationCauseCode , TraitEngine } ;
117- use rustc:: ty:: { self , AdtKind , Ty , TyCtxt , GenericParamDefKind , Visibility , ToPredicate ,
118- RegionKind } ;
117+ use rustc:: ty:: { self , AdtKind , Ty , TyCtxt , GenericParamDefKind , RegionKind , Visibility ,
118+ ToPolyTraitRef , ToPredicate } ;
119119use rustc:: ty:: adjustment:: { Adjust , Adjustment , AllowTwoPhase , AutoBorrow , AutoBorrowMutability } ;
120120use rustc:: ty:: fold:: TypeFoldable ;
121121use rustc:: ty:: query:: Providers ;
@@ -143,6 +143,7 @@ use require_c_abi_if_variadic;
143143use session:: { CompileIncomplete , config, Session } ;
144144use TypeAndSubsts ;
145145use lint;
146+ use util:: captures:: Captures ;
146147use util:: common:: { ErrorReported , indenter} ;
147148use util:: nodemap:: { DefIdMap , DefIdSet , FxHashMap , FxHashSet , NodeMap } ;
148149
@@ -2732,6 +2733,72 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
27322733 method. sig . output ( )
27332734 }
27342735
2736+ fn self_type_matches_expected_vid (
2737+ & self ,
2738+ trait_ref : ty:: PolyTraitRef < ' tcx > ,
2739+ expected_vid : ty:: TyVid ,
2740+ ) -> bool {
2741+ let self_ty = self . shallow_resolve ( trait_ref. self_ty ( ) ) ;
2742+ debug ! (
2743+ "self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?}, expected_vid={:?})" ,
2744+ trait_ref, self_ty, expected_vid
2745+ ) ;
2746+ match self_ty. sty {
2747+ ty:: Infer ( ty:: TyVar ( found_vid) ) => {
2748+ // FIXME: consider using `sub_root_var` here so we
2749+ // can see through subtyping.
2750+ let found_vid = self . root_var ( found_vid) ;
2751+ debug ! ( "self_type_matches_expected_vid - found_vid={:?}" , found_vid) ;
2752+ expected_vid == found_vid
2753+ }
2754+ _ => false
2755+ }
2756+ }
2757+
2758+ fn obligations_for_self_ty < ' b > ( & ' b self , self_ty : ty:: TyVid )
2759+ -> impl Iterator < Item =( ty:: PolyTraitRef < ' tcx > , traits:: PredicateObligation < ' tcx > ) >
2760+ + Captures < ' gcx > + ' b
2761+ {
2762+ // FIXME: consider using `sub_root_var` here so we
2763+ // can see through subtyping.
2764+ let ty_var_root = self . root_var ( self_ty) ;
2765+ debug ! ( "obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}" ,
2766+ self_ty, ty_var_root,
2767+ self . fulfillment_cx. borrow( ) . pending_obligations( ) ) ;
2768+
2769+ self . fulfillment_cx
2770+ . borrow ( )
2771+ . pending_obligations ( )
2772+ . into_iter ( )
2773+ . filter_map ( move |obligation| match obligation. predicate {
2774+ ty:: Predicate :: Projection ( ref data) =>
2775+ Some ( ( data. to_poly_trait_ref ( self . tcx ) , obligation) ) ,
2776+ ty:: Predicate :: Trait ( ref data) =>
2777+ Some ( ( data. to_poly_trait_ref ( ) , obligation) ) ,
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 ( move |( tr, _) | self . self_type_matches_expected_vid ( * tr, ty_var_root) )
2794+ }
2795+
2796+ fn type_var_is_sized ( & self , self_ty : ty:: TyVid ) -> bool {
2797+ self . obligations_for_self_ty ( self_ty) . any ( |( tr, _) | {
2798+ Some ( tr. def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( )
2799+ } )
2800+ }
2801+
27352802 /// Generic function that factors out common logic from function calls,
27362803 /// method calls and overloaded operators.
27372804 fn check_argument_types ( & self ,
0 commit comments