@@ -15,7 +15,7 @@ use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
15
15
use rustc:: mir:: { ConstraintCategory , UserTypeAnnotation } ;
16
16
use rustc:: traits:: query:: Fallible ;
17
17
use rustc:: ty:: relate:: TypeRelation ;
18
- use rustc:: ty:: subst:: UserSubsts ;
18
+ use rustc:: ty:: subst:: { Subst , UserSelfTy , UserSubsts } ;
19
19
use rustc:: ty:: { self , Ty } ;
20
20
use syntax_pos:: DUMMY_SP ;
21
21
@@ -98,9 +98,24 @@ pub(super) fn relate_type_and_user_type<'tcx>(
98
98
} ,
99
99
_,
100
100
) = infcx. instantiate_canonical_with_fresh_inference_vars ( DUMMY_SP , & canonical_substs) ;
101
- assert ! ( user_self_ty. is_none( ) ) ; // TODO for now
102
101
let ty = infcx. tcx . mk_fn_def ( def_id, substs) ;
102
+
103
103
type_relating. relate ( & ty, & a) ?;
104
+
105
+ if let Some ( UserSelfTy {
106
+ impl_def_id,
107
+ self_ty,
108
+ } ) = user_self_ty
109
+ {
110
+ let impl_self_ty = infcx. tcx . type_of ( impl_def_id) ;
111
+ let impl_self_ty = impl_self_ty. subst ( infcx. tcx , & substs) ;
112
+ type_relating. relate_with_variance (
113
+ ty:: Variance :: Invariant ,
114
+ & self_ty,
115
+ & impl_self_ty,
116
+ ) ?;
117
+ }
118
+
104
119
Ok ( ty)
105
120
}
106
121
UserTypeAnnotation :: AdtDef ( adt_def, canonical_substs) => {
@@ -111,7 +126,10 @@ pub(super) fn relate_type_and_user_type<'tcx>(
111
126
} ,
112
127
_,
113
128
) = infcx. instantiate_canonical_with_fresh_inference_vars ( DUMMY_SP , & canonical_substs) ;
114
- assert ! ( user_self_ty. is_none( ) ) ; // TODO for now
129
+
130
+ // We don't extract adt-defs with a self-type.
131
+ assert ! ( user_self_ty. is_none( ) ) ;
132
+
115
133
let ty = infcx. tcx . mk_adt ( adt_def, substs) ;
116
134
type_relating. relate ( & ty, & a) ?;
117
135
Ok ( ty)
0 commit comments