@@ -113,8 +113,8 @@ use rustc::mir::interpret::{ConstValue, GlobalId};
113
113
use rustc:: ty:: subst:: { CanonicalUserSubsts , UnpackedKind , Subst , Substs ,
114
114
UserSelfTy , UserSubsts } ;
115
115
use rustc:: traits:: { self , ObligationCause , ObligationCauseCode , TraitEngine } ;
116
- use rustc:: ty:: { self , AdtKind , Ty , TyCtxt , GenericParamDefKind , Visibility , ToPredicate ,
117
- RegionKind } ;
116
+ use rustc:: ty:: { self , AdtKind , Ty , TyCtxt , GenericParamDefKind , RegionKind , Visibility ,
117
+ ToPolyTraitRef , ToPredicate } ;
118
118
use rustc:: ty:: adjustment:: { Adjust , Adjustment , AllowTwoPhase , AutoBorrow , AutoBorrowMutability } ;
119
119
use rustc:: ty:: fold:: TypeFoldable ;
120
120
use rustc:: ty:: query:: Providers ;
@@ -142,6 +142,7 @@ use require_c_abi_if_variadic;
142
142
use session:: { CompileIncomplete , config, Session } ;
143
143
use TypeAndSubsts ;
144
144
use lint;
145
+ use util:: captures:: Captures ;
145
146
use util:: common:: { ErrorReported , indenter} ;
146
147
use util:: nodemap:: { DefIdMap , DefIdSet , FxHashMap , FxHashSet , NodeMap } ;
147
148
@@ -2731,6 +2732,72 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2731
2732
method. sig . output ( )
2732
2733
}
2733
2734
2735
+ fn self_type_matches_expected_vid (
2736
+ & self ,
2737
+ trait_ref : ty:: PolyTraitRef < ' tcx > ,
2738
+ expected_vid : ty:: TyVid ,
2739
+ ) -> bool {
2740
+ let self_ty = self . shallow_resolve ( trait_ref. self_ty ( ) ) ;
2741
+ debug ! (
2742
+ "self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?}, expected_vid={:?})" ,
2743
+ trait_ref, self_ty, expected_vid
2744
+ ) ;
2745
+ match self_ty. sty {
2746
+ ty:: Infer ( ty:: TyVar ( found_vid) ) => {
2747
+ // FIXME: consider using `sub_root_var` here so we
2748
+ // can see through subtyping.
2749
+ let found_vid = self . root_var ( found_vid) ;
2750
+ debug ! ( "self_type_matches_expected_vid - found_vid={:?}" , found_vid) ;
2751
+ expected_vid == found_vid
2752
+ }
2753
+ _ => false
2754
+ }
2755
+ }
2756
+
2757
+ fn obligations_for_self_ty < ' b > ( & ' b self , self_ty : ty:: TyVid )
2758
+ -> impl Iterator < Item =( ty:: PolyTraitRef < ' tcx > , traits:: PredicateObligation < ' tcx > ) >
2759
+ + Captures < ' gcx > + ' b
2760
+ {
2761
+ // FIXME: consider using `sub_root_var` here so we
2762
+ // can see through subtyping.
2763
+ let ty_var_root = self . root_var ( self_ty) ;
2764
+ debug ! ( "obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}" ,
2765
+ self_ty, ty_var_root,
2766
+ self . fulfillment_cx. borrow( ) . pending_obligations( ) ) ;
2767
+
2768
+ self . fulfillment_cx
2769
+ . borrow ( )
2770
+ . pending_obligations ( )
2771
+ . into_iter ( )
2772
+ . filter_map ( move |obligation| match obligation. predicate {
2773
+ ty:: Predicate :: Projection ( ref data) =>
2774
+ Some ( ( data. to_poly_trait_ref ( self . tcx ) , obligation) ) ,
2775
+ ty:: Predicate :: Trait ( ref data) =>
2776
+ Some ( ( data. to_poly_trait_ref ( ) , obligation) ) ,
2777
+ ty:: Predicate :: Subtype ( ..) => None ,
2778
+ ty:: Predicate :: RegionOutlives ( ..) => None ,
2779
+ ty:: Predicate :: TypeOutlives ( ..) => None ,
2780
+ ty:: Predicate :: WellFormed ( ..) => None ,
2781
+ ty:: Predicate :: ObjectSafe ( ..) => None ,
2782
+ ty:: Predicate :: ConstEvaluatable ( ..) => None ,
2783
+ // N.B., this predicate is created by breaking down a
2784
+ // `ClosureType: FnFoo()` predicate, where
2785
+ // `ClosureType` represents some `Closure`. It can't
2786
+ // possibly be referring to the current closure,
2787
+ // because we haven't produced the `Closure` for
2788
+ // this closure yet; this is exactly why the other
2789
+ // code is looking for a self type of a unresolved
2790
+ // inference variable.
2791
+ ty:: Predicate :: ClosureKind ( ..) => None ,
2792
+ } ) . filter ( move |( tr, _) | self . self_type_matches_expected_vid ( * tr, ty_var_root) )
2793
+ }
2794
+
2795
+ fn type_var_is_sized ( & self , self_ty : ty:: TyVid ) -> bool {
2796
+ self . obligations_for_self_ty ( self_ty) . any ( |( tr, _) | {
2797
+ Some ( tr. def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( )
2798
+ } )
2799
+ }
2800
+
2734
2801
/// Generic function that factors out common logic from function calls,
2735
2802
/// method calls and overloaded operators.
2736
2803
fn check_argument_types ( & self ,
0 commit comments