diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index b660187945cd..4c3e084af4d7 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -597,7 +597,7 @@ impl<'a, 'gcx> HashStable> for mir::UserTypeAnnotation< mir::UserTypeAnnotation::Ty(ref ty) => { ty.hash_stable(hcx, hasher); } - mir::UserTypeAnnotation::FnDef(ref def_id, ref substs) => { + mir::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => { def_id.hash_stable(hcx, hasher); substs.hash_stable(hcx, hasher); } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9a0623ca5393..8dcb14485f57 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2425,14 +2425,21 @@ pub struct Constant<'tcx> { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub enum UserTypeAnnotation<'tcx> { Ty(CanonicalTy<'tcx>), - FnDef(DefId, CanonicalUserSubsts<'tcx>), + + /// The canonical type is the result of `type_of(def_id)` with the + /// given substitutions applied. + TypeOf(DefId, CanonicalUserSubsts<'tcx>), + + /// The canonical type is the given ADT with the given + /// substitutions applied (in this case, `user_self_ty` had better + /// be `None`). AdtDef(&'tcx AdtDef, CanonicalUserSubsts<'tcx>), } EnumTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for UserTypeAnnotation<'tcx> { (UserTypeAnnotation::Ty)(ty), - (UserTypeAnnotation::FnDef)(def, substs), + (UserTypeAnnotation::TypeOf)(def, substs), (UserTypeAnnotation::AdtDef)(def, substs), } } 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 72120eb18413..2ccfe6a73a28 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 @@ -90,7 +90,7 @@ pub(super) fn relate_type_and_user_type<'tcx>( type_relating.relate(&ty, &a)?; Ok(ty) } - UserTypeAnnotation::FnDef(def_id, canonical_substs) => { + UserTypeAnnotation::TypeOf(def_id, canonical_substs) => { let ( UserSubsts { substs, @@ -98,7 +98,9 @@ pub(super) fn relate_type_and_user_type<'tcx>( }, _, ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs); - let ty = infcx.tcx.mk_fn_def(def_id, substs); + + let ty = infcx.tcx.type_of(def_id); + let ty = ty.subst(infcx.tcx, substs); type_relating.relate(&ty, &a)?; diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 56a29f29d685..621e0d1b10cf 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -772,7 +772,7 @@ fn user_substs_applied_to_def( Def::Method(_) | Def::StructCtor(_, CtorKind::Fn) | Def::VariantCtor(_, CtorKind::Fn) => - Some(UserTypeAnnotation::FnDef(def.def_id(), cx.tables().user_substs(hir_id)?)), + Some(UserTypeAnnotation::TypeOf(def.def_id(), cx.tables().user_substs(hir_id)?)), Def::Const(_def_id) | Def::AssociatedConst(_def_id) => diff --git a/src/librustc_mir/hair/util.rs b/src/librustc_mir/hair/util.rs index 71cbac6b7c88..fa5f2be62b80 100644 --- a/src/librustc_mir/hair/util.rs +++ b/src/librustc_mir/hair/util.rs @@ -36,7 +36,7 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> { let user_substs = self.tables().user_substs(hir_id)?; match &self.tables().node_id_to_type(hir_id).sty { ty::Adt(adt_def, _) => Some(UserTypeAnnotation::AdtDef(adt_def, user_substs)), - ty::FnDef(def_id, _) => Some(UserTypeAnnotation::FnDef(*def_id, user_substs)), + ty::FnDef(def_id, _) => Some(UserTypeAnnotation::TypeOf(*def_id, user_substs)), sty => bug!( "sty: {:?} should not have user-substs {:?} recorded ", sty,