@@ -16,7 +16,7 @@ use rustc::mir::{ConstraintCategory, UserTypeAnnotation};
1616use rustc:: traits:: query:: Fallible ;
1717use rustc:: ty:: relate:: TypeRelation ;
1818use rustc:: ty:: subst:: { Subst , UserSelfTy , UserSubsts } ;
19- use rustc:: ty:: { self , Ty } ;
19+ use rustc:: ty:: { self , Ty , TypeFoldable } ;
2020use syntax_pos:: DUMMY_SP ;
2121
2222/// Adds sufficient constraints to ensure that `a <: b`.
@@ -109,6 +109,18 @@ pub(super) fn relate_type_and_user_type<'tcx>(
109109 {
110110 let impl_self_ty = infcx. tcx . type_of ( impl_def_id) ;
111111 let impl_self_ty = impl_self_ty. subst ( infcx. tcx , & substs) ;
112+
113+ // There may be type variables in `substs` and hence
114+ // in `impl_self_ty`, but they should all have been
115+ // resolved to some fixed value during the first call
116+ // to `relate`, above. Therefore, if we use
117+ // `resolve_type_vars_if_possible` we should get to
118+ // something without type variables. This is important
119+ // because the `b` type in `relate_with_variance`
120+ // below is not permitted to have inference variables.
121+ let impl_self_ty = infcx. resolve_type_vars_if_possible ( & impl_self_ty) ;
122+ assert ! ( !impl_self_ty. has_infer_types( ) ) ;
123+
112124 type_relating. relate_with_variance (
113125 ty:: Variance :: Invariant ,
114126 & self_ty,
0 commit comments