convert FnDef
to TypeOf
, which is more general
This commit is contained in:
parent
bd93741bd3
commit
ebdfda64f8
@ -597,7 +597,7 @@ fn hash_stable<W: StableHasherResult>(&self,
|
||||
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);
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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)?;
|
||||
|
||||
|
@ -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) =>
|
||||
|
@ -36,7 +36,7 @@ fn user_substs_applied_to_ty_of_hir_id(
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user