self.late_module_passes.push(Box::new(pass));
}
- // Helper method for register_early/late_pass
+ /// Helper method for register_early/late_pass
pub fn register_lints(&mut self, lints: &[&'static Lint]) {
for lint in lints {
self.lints.push(lint);
AbsolutePathPrinter { tcx: self.tcx }.print_def_path(def_id, &[]).unwrap()
}
+
+ /// 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()
+ })
+ }
}
impl<'tcx> abi::HasDataLayout for LateContext<'tcx> {