Skip to content

Commit ba20806

Browse files
committed
avoid type variables in the self-type
1 parent 16a3824 commit ba20806

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::mir::{ConstraintCategory, UserTypeAnnotation};
1616
use rustc::traits::query::Fallible;
1717
use rustc::ty::relate::TypeRelation;
1818
use rustc::ty::subst::{Subst, UserSelfTy, UserSubsts};
19-
use rustc::ty::{self, Ty};
19+
use rustc::ty::{self, Ty, TypeFoldable};
2020
use 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

Comments
 (0)