From 0e69a8ad20522467ea1b0c32720bbc7faa1eef13 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 4 Aug 2023 17:44:41 -0300 Subject: [PATCH] Add all_trait_decls to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 8 ++++++++ compiler/rustc_smir/src/stable_mir/mod.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 239b61b433d..d12de92db8a 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -42,6 +42,14 @@ impl<'tcx> Context for Tables<'tcx> { Some(self.crate_item(self.tcx.entry_fn(())?.0)) } + fn all_trait_decls(&mut self) -> stable_mir::TraitDecls { + self.tcx + .traits(LOCAL_CRATE) + .iter() + .map(|trait_def_id| self.trait_def(*trait_def_id)) + .collect() + } + fn trait_decl(&mut self, trait_def: &stable_mir::ty::TraitDef) -> stable_mir::ty::TraitDecl { let def_id = self.trait_def_id(trait_def); let trait_def = self.tcx.trait_def(def_id); diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 0f32f07dcb5..d93f25249b9 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -32,6 +32,9 @@ pub type DefId = usize; /// A list of crate items. pub type CrateItems = Vec; +/// A list of crate items. +pub type TraitDecls = Vec; + /// Holds information about a crate. #[derive(Clone, PartialEq, Eq, Debug)] pub struct Crate { @@ -84,6 +87,7 @@ pub trait Context { /// Retrieve all items of the local crate that have a MIR associated with them. fn all_local_items(&mut self) -> CrateItems; fn mir_body(&mut self, item: &CrateItem) -> mir::Body; + fn all_trait_decls(&mut self) -> TraitDecls; fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl; /// Get information about the local crate. fn local_crate(&self) -> Crate;