Skip to content

Commit ebdfda6

Browse files
committed
convert FnDef to TypeOf, which is more general
1 parent bd93741 commit ebdfda6

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<
597597
mir::UserTypeAnnotation::Ty(ref ty) => {
598598
ty.hash_stable(hcx, hasher);
599599
}
600-
mir::UserTypeAnnotation::FnDef(ref def_id, ref substs) => {
600+
mir::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => {
601601
def_id.hash_stable(hcx, hasher);
602602
substs.hash_stable(hcx, hasher);
603603
}

src/librustc/mir/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,14 +2425,21 @@ pub struct Constant<'tcx> {
24252425
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
24262426
pub enum UserTypeAnnotation<'tcx> {
24272427
Ty(CanonicalTy<'tcx>),
2428-
FnDef(DefId, CanonicalUserSubsts<'tcx>),
2428+
2429+
/// The canonical type is the result of `type_of(def_id)` with the
2430+
/// given substitutions applied.
2431+
TypeOf(DefId, CanonicalUserSubsts<'tcx>),
2432+
2433+
/// The canonical type is the given ADT with the given
2434+
/// substitutions applied (in this case, `user_self_ty` had better
2435+
/// be `None`).
24292436
AdtDef(&'tcx AdtDef, CanonicalUserSubsts<'tcx>),
24302437
}
24312438

24322439
EnumTypeFoldableImpl! {
24332440
impl<'tcx> TypeFoldable<'tcx> for UserTypeAnnotation<'tcx> {
24342441
(UserTypeAnnotation::Ty)(ty),
2435-
(UserTypeAnnotation::FnDef)(def, substs),
2442+
(UserTypeAnnotation::TypeOf)(def, substs),
24362443
(UserTypeAnnotation::AdtDef)(def, substs),
24372444
}
24382445
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ pub(super) fn relate_type_and_user_type<'tcx>(
9090
type_relating.relate(&ty, &a)?;
9191
Ok(ty)
9292
}
93-
UserTypeAnnotation::FnDef(def_id, canonical_substs) => {
93+
UserTypeAnnotation::TypeOf(def_id, canonical_substs) => {
9494
let (
9595
UserSubsts {
9696
substs,
9797
user_self_ty,
9898
},
9999
_,
100100
) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
101-
let ty = infcx.tcx.mk_fn_def(def_id, substs);
101+
102+
let ty = infcx.tcx.type_of(def_id);
103+
let ty = ty.subst(infcx.tcx, substs);
102104

103105
type_relating.relate(&ty, &a)?;
104106

src/librustc_mir/hair/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ fn user_substs_applied_to_def(
772772
Def::Method(_) |
773773
Def::StructCtor(_, CtorKind::Fn) |
774774
Def::VariantCtor(_, CtorKind::Fn) =>
775-
Some(UserTypeAnnotation::FnDef(def.def_id(), cx.tables().user_substs(hir_id)?)),
775+
Some(UserTypeAnnotation::TypeOf(def.def_id(), cx.tables().user_substs(hir_id)?)),
776776

777777
Def::Const(_def_id) |
778778
Def::AssociatedConst(_def_id) =>

src/librustc_mir/hair/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> {
3636
let user_substs = self.tables().user_substs(hir_id)?;
3737
match &self.tables().node_id_to_type(hir_id).sty {
3838
ty::Adt(adt_def, _) => Some(UserTypeAnnotation::AdtDef(adt_def, user_substs)),
39-
ty::FnDef(def_id, _) => Some(UserTypeAnnotation::FnDef(*def_id, user_substs)),
39+
ty::FnDef(def_id, _) => Some(UserTypeAnnotation::TypeOf(*def_id, user_substs)),
4040
sty => bug!(
4141
"sty: {:?} should not have user-substs {:?} recorded ",
4242
sty,

0 commit comments

Comments
 (0)