+
+ /// Returns the associated type `name` for `self_ty` as an implementation of `trait_id`.
+ /// Do not invoke without first verifying that the type implements the trait.
+ pub fn get_associated_type(
+ &self,
+ self_ty: Ty<'tcx>,
+ trait_id: DefId,
+ name: &str,
+ ) -> Option<Ty<'tcx>> {
+ let tcx = self.tcx;
+ tcx.associated_items(trait_id)
+ .find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
+ .and_then(|assoc| {
+ let proj = tcx.mk_projection(assoc.def_id, tcx.mk_substs_trait(self_ty, []));
+ tcx.try_normalize_erasing_regions(self.param_env, proj).ok()
+ })
+ }