]> git.proxmox.com Git - rustc.git/blame - src/librustc_mir_build/hair/util.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_mir_build / hair / util.rs
CommitLineData
dfeec247 1use rustc_hir as hir;
ba9703b0 2use rustc_middle::ty::{self, CanonicalUserType, TyCtxt, UserType};
0bf4aa26 3
dc9dc135
XL
4crate trait UserAnnotatedTyHelpers<'tcx> {
5 fn tcx(&self) -> TyCtxt<'tcx>;
0bf4aa26
XL
6
7 fn tables(&self) -> &ty::TypeckTables<'tcx>;
8
0bf4aa26
XL
9 /// Looks up the type associated with this hir-id and applies the
10 /// user-given substitutions; the hir-id must map to a suitable
11 /// type.
12 fn user_substs_applied_to_ty_of_hir_id(
13 &self,
14 hir_id: hir::HirId,
9fa01778 15 ) -> Option<CanonicalUserType<'tcx>> {
0731742a
XL
16 let user_provided_types = self.tables().user_provided_types();
17 let mut user_ty = *user_provided_types.get(hir_id)?;
18 debug!("user_subts_applied_to_ty_of_hir_id: user_ty={:?}", user_ty);
532ac7d7 19 let ty = self.tables().node_type(hir_id);
e74abb32 20 match ty.kind {
0731742a 21 ty::Adt(adt_def, ..) => {
9fa01778 22 if let UserType::TypeOf(ref mut did, _) = &mut user_ty.value {
0731742a
XL
23 *did = adt_def.did;
24 }
25 Some(user_ty)
26 }
27 ty::FnDef(..) => Some(user_ty),
dfeec247 28 _ => bug!("ty: {:?} should not have user provided type {:?} recorded ", ty, user_ty),
0bf4aa26
XL
29 }
30 }
31}