adt_def: adt,
variant_index: 0,
substs,
- user_ty: cx.user_annotated_ty_for_adt(expr.hir_id, adt),
+ user_ty: cx.user_substs_applied_to_adt(expr.hir_id, adt),
fields: field_refs(cx, fields),
base: base.as_ref().map(|base| {
FruInfo {
adt_def: adt,
variant_index: index,
substs,
- user_ty: cx.user_annotated_ty_for_adt(expr.hir_id, adt),
+ user_ty: cx.user_substs_applied_to_adt(expr.hir_id, adt),
fields: field_refs(cx, fields),
base: None,
}
// user.
Def::StructCtor(_def_id, CtorKind::Const) |
Def::VariantCtor(_def_id, CtorKind::Const) =>
- match &cx.tables().node_id_to_type(hir_id).sty {
- ty::Adt(adt_def, _) => cx.user_annotated_ty_for_adt(hir_id, adt_def),
- sty => bug!("unexpected sty: {:?}", sty),
- },
+ cx.user_substs_applied_to_ty_of_hir_id(hir_id),
// `Self` is used in expression as a tuple struct constructor or an unit struct constructor
- Def::SelfCtor(_) => {
- let sty = &cx.tables().node_id_to_type(hir_id).sty;
- match sty {
- ty::FnDef(ref def_id, _) => {
- Some(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_id, user_substs)
- }))
- }
- ty::Adt(ref adt_def, _) => {
- cx.user_annotated_ty_for_adt(hir_id, adt_def)
- }
- _ => {
- bug!("unexpected sty: {:?}", sty)
- }
- }
- }
+ Def::SelfCtor(_) =>
+ cx.user_substs_applied_to_ty_of_hir_id(hir_id),
+
_ =>
bug!("user_annotated_ty_for_def: unexpected def {:?} at {:?}", def, hir_id)
}
adt_def,
variant_index: adt_def.variant_index_with_id(def_id),
substs,
- user_ty: cx.user_annotated_ty_for_adt(expr.hir_id, adt_def),
+ user_ty: cx.user_substs_applied_to_adt(expr.hir_id, adt_def),
fields: vec![],
base: None,
}
fn tables(&self) -> &ty::TypeckTables<'tcx>;
- fn user_annotated_ty_for_adt(
+ fn user_substs_applied_to_adt(
&self,
hir_id: hir::HirId,
adt_def: &'tcx AdtDef,
self.tcx().mk_adt(adt_def, user_substs)
}))
}
+
+ /// Looks up the type associated with this hir-id and applies the
+ /// user-given substitutions; the hir-id must map to a suitable
+ /// type.
+ fn user_substs_applied_to_ty_of_hir_id(&self, hir_id: hir::HirId) -> Option<CanonicalTy<'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(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(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)
+ })),
+ sty => bug!(
+ "sty: {:?} should not have user-substs {:?} recorded ",
+ sty,
+ user_substs
+ ),
+ }
+ }
}