2 use rustc_middle::ty::{self, CanonicalUserType, TyCtxt, UserType};
4 crate trait UserAnnotatedTyHelpers<'tcx> {
5 fn tcx(&self) -> TyCtxt<'tcx>;
7 fn typeck_results(&self) -> &ty::TypeckResults<'tcx>;
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
12 fn user_substs_applied_to_ty_of_hir_id(
15 ) -> Option<CanonicalUserType<'tcx>> {
16 let user_provided_types = self.typeck_results().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);
19 let ty = self.typeck_results().node_type(hir_id);
21 ty::Adt(adt_def, ..) => {
22 if let UserType::TypeOf(ref mut did, _) = &mut user_ty.value {
27 ty::FnDef(..) => Some(user_ty),
28 _ => bug!("ty: {:?} should not have user provided type {:?} recorded ", ty, user_ty),