Skip to content

Commit 547182e

Browse files
committed
handle user-self-type for def-ids
1 parent 0e1d362 commit 547182e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
1515
use rustc::mir::{ConstraintCategory, UserTypeAnnotation};
1616
use rustc::traits::query::Fallible;
1717
use rustc::ty::relate::TypeRelation;
18-
use rustc::ty::subst::UserSubsts;
18+
use rustc::ty::subst::{Subst, UserSelfTy, UserSubsts};
1919
use rustc::ty::{self, Ty};
2020
use syntax_pos::DUMMY_SP;
2121

@@ -98,9 +98,24 @@ pub(super) fn relate_type_and_user_type<'tcx>(
9898
},
9999
_,
100100
) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
101-
assert!(user_self_ty.is_none()); // TODO for now
102101
let ty = infcx.tcx.mk_fn_def(def_id, substs);
102+
103103
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+
104119
Ok(ty)
105120
}
106121
UserTypeAnnotation::AdtDef(adt_def, canonical_substs) => {
@@ -111,7 +126,10 @@ pub(super) fn relate_type_and_user_type<'tcx>(
111126
},
112127
_,
113128
) = 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+
115133
let ty = infcx.tcx.mk_adt(adt_def, substs);
116134
type_relating.relate(&ty, &a)?;
117135
Ok(ty)

0 commit comments

Comments
 (0)