Skip to content

Commit

Permalink
Add all_trait_decls to SMIR
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Aug 7, 2023
1 parent 496faa8 commit 0e69a8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_smir/src/stable_mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub type DefId = usize;
/// A list of crate items.
pub type CrateItems = Vec<CrateItem>;

/// A list of crate items.
pub type TraitDecls = Vec<TraitDef>;

/// Holds information about a crate.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Crate {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0e69a8a

Please sign in to comment.