diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-10-11 18:06:30 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-10-15 16:25:08 -0400 |
| commit | 547182ea9463cdc4cf72f0af1372f4db17f700e8 (patch) | |
| tree | f5f9b5e440c1c0bd0b9640ee7f34539a6a5a04d1 | |
| parent | 0e1d3624e990e84299ab75926c865f19353e9b2f (diff) | |
| download | rust-547182ea9463cdc4cf72f0af1372f4db17f700e8.tar.gz rust-547182ea9463cdc4cf72f0af1372f4db17f700e8.zip | |
handle user-self-type for def-ids
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs index f59bcd53fa7..a345d0484cf 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs @@ -15,7 +15,7 @@ use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc::mir::{ConstraintCategory, UserTypeAnnotation}; use rustc::traits::query::Fallible; use rustc::ty::relate::TypeRelation; -use rustc::ty::subst::UserSubsts; +use rustc::ty::subst::{Subst, UserSelfTy, UserSubsts}; use rustc::ty::{self, Ty}; use syntax_pos::DUMMY_SP; @@ -98,9 +98,24 @@ pub(super) fn relate_type_and_user_type<'tcx>( }, _, ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs); - assert!(user_self_ty.is_none()); // TODO for now let ty = infcx.tcx.mk_fn_def(def_id, substs); + type_relating.relate(&ty, &a)?; + + if let Some(UserSelfTy { + impl_def_id, + self_ty, + }) = user_self_ty + { + let impl_self_ty = infcx.tcx.type_of(impl_def_id); + let impl_self_ty = impl_self_ty.subst(infcx.tcx, &substs); + type_relating.relate_with_variance( + ty::Variance::Invariant, + &self_ty, + &impl_self_ty, + )?; + } + Ok(ty) } UserTypeAnnotation::AdtDef(adt_def, canonical_substs) => { @@ -111,7 +126,10 @@ pub(super) fn relate_type_and_user_type<'tcx>( }, _, ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs); - assert!(user_self_ty.is_none()); // TODO for now + + // We don't extract adt-defs with a self-type. + assert!(user_self_ty.is_none()); + let ty = infcx.tcx.mk_adt(adt_def, substs); type_relating.relate(&ty, &a)?; Ok(ty) |
