introduce FnDef and AdtDef to UserTypeAnnotation
This commit is contained in:
parent
aed6e4a083
commit
2a7fc227a6
5 changed files with 32 additions and 40 deletions
|
|
@ -597,6 +597,14 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<
|
|||
mir::UserTypeAnnotation::Ty(ref ty) => {
|
||||
ty.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::UserTypeAnnotation::FnDef(ref def_id, ref substs) => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::UserTypeAnnotation::AdtDef(ref def_id, ref substs) => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ use syntax::ast::{self, Name};
|
|||
use syntax::symbol::InternedString;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use ty::subst::{Subst, Substs};
|
||||
use ty::subst::{CanonicalSubsts, Subst, Substs};
|
||||
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
|
||||
use util::ppaux;
|
||||
|
||||
|
|
@ -2413,11 +2413,15 @@ pub struct Constant<'tcx> {
|
|||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum UserTypeAnnotation<'tcx> {
|
||||
Ty(CanonicalTy<'tcx>),
|
||||
FnDef(DefId, CanonicalSubsts<'tcx>),
|
||||
AdtDef(&'tcx AdtDef, CanonicalSubsts<'tcx>),
|
||||
}
|
||||
|
||||
EnumTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for UserTypeAnnotation<'tcx> {
|
||||
(UserTypeAnnotation::Ty)(ty),
|
||||
(UserTypeAnnotation::FnDef)(def, substs),
|
||||
(UserTypeAnnotation::AdtDef)(def, substs),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,9 +71,21 @@ pub(super) fn relate_type_and_user_type<'tcx>(
|
|||
a, v, user_ty, locations
|
||||
);
|
||||
|
||||
let (b, _values) = match user_ty {
|
||||
let b = match user_ty {
|
||||
UserTypeAnnotation::Ty(canonical_ty) => {
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_ty)
|
||||
let (ty, _) =
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_ty);
|
||||
ty
|
||||
}
|
||||
UserTypeAnnotation::FnDef(def_id, canonical_substs) => {
|
||||
let (substs, _) =
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
|
||||
infcx.tcx.mk_fn_def(def_id, substs)
|
||||
}
|
||||
UserTypeAnnotation::AdtDef(adt_def, canonical_substs) => {
|
||||
let (substs, _) =
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
|
||||
infcx.tcx.mk_adt(adt_def, substs)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -295,13 +295,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||
let substs = cx.tables().node_substs(fun.hir_id);
|
||||
|
||||
let user_ty = cx.tables().user_substs(fun.hir_id)
|
||||
.map(|user_substs| {
|
||||
UserTypeAnnotation::Ty(user_substs.unchecked_map(|user_substs| {
|
||||
// Here, we just pair an `AdtDef` with the
|
||||
// `user_substs`, so no new types etc are introduced.
|
||||
cx.tcx().mk_adt(adt_def, user_substs)
|
||||
}))
|
||||
});
|
||||
.map(|user_substs| UserTypeAnnotation::AdtDef(adt_def, user_substs));
|
||||
|
||||
let field_refs = args.iter()
|
||||
.enumerate()
|
||||
|
|
@ -774,14 +768,7 @@ fn user_substs_applied_to_def(
|
|||
Def::Method(_) |
|
||||
Def::StructCtor(_, CtorKind::Fn) |
|
||||
Def::VariantCtor(_, CtorKind::Fn) =>
|
||||
Some(
|
||||
UserTypeAnnotation::Ty(cx.tables().user_substs(hir_id)?.unchecked_map(|user_substs| {
|
||||
// Here, we just pair a `DefId` with the
|
||||
// `user_substs`, so no new types etc are introduced.
|
||||
cx.tcx().mk_fn_def(def.def_id(), user_substs)
|
||||
}),
|
||||
)
|
||||
),
|
||||
Some(UserTypeAnnotation::FnDef(def.def_id(), cx.tables().user_substs(hir_id)?)),
|
||||
|
||||
Def::Const(_def_id) |
|
||||
Def::AssociatedConst(_def_id) =>
|
||||
|
|
|
|||
|
|
@ -23,13 +23,7 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> {
|
|||
adt_def: &'tcx AdtDef,
|
||||
) -> Option<UserTypeAnnotation<'tcx>> {
|
||||
let user_substs = self.tables().user_substs(hir_id)?;
|
||||
Some(UserTypeAnnotation::Ty(user_substs.unchecked_map(
|
||||
|user_substs| {
|
||||
// Here, we just pair an `AdtDef` with the
|
||||
// `user_substs`, so no new types etc are introduced.
|
||||
self.tcx().mk_adt(adt_def, user_substs)
|
||||
},
|
||||
)))
|
||||
Some(UserTypeAnnotation::AdtDef(adt_def, user_substs))
|
||||
}
|
||||
|
||||
/// Looks up the type associated with this hir-id and applies the
|
||||
|
|
@ -41,21 +35,8 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> {
|
|||
) -> Option<UserTypeAnnotation<'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::Ty(user_substs.unchecked_map(
|
||||
|user_substs| {
|
||||
// Ok to call `unchecked_map` because we just pair an
|
||||
// `AdtDef` with the `user_substs`, so no new types
|
||||
// etc are introduced.
|
||||
self.tcx().mk_adt(adt_def, user_substs)
|
||||
},
|
||||
))),
|
||||
ty::FnDef(def_id, _) => Some(UserTypeAnnotation::Ty(user_substs.unchecked_map(
|
||||
|user_substs| {
|
||||
// Here, we just pair a `DefId` with the
|
||||
// `user_substs`, so no new types etc are introduced.
|
||||
self.tcx().mk_fn_def(*def_id, user_substs)
|
||||
},
|
||||
))),
|
||||
ty::Adt(adt_def, _) => Some(UserTypeAnnotation::AdtDef(adt_def, user_substs)),
|
||||
ty::FnDef(def_id, _) => Some(UserTypeAnnotation::FnDef(*def_id, user_substs)),
|
||||
sty => bug!(
|
||||
"sty: {:?} should not have user-substs {:?} recorded ",
|
||||
sty,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue