Skip to content

Commit a9de0c5

Browse files
committed
Allow fetching the SMIR body of FnDefs
1 parent 8764b87 commit a9de0c5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impl<'tcx> Context for Tables<'tcx> {
7272
impl_trait.stable(self)
7373
}
7474

75-
fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body {
76-
let def_id = self[item.0];
75+
fn mir_body(&mut self, item: stable_mir::DefId) -> stable_mir::mir::Body {
76+
let def_id = self[item];
7777
let mir = self.tcx.optimized_mir(def_id);
7878
stable_mir::mir::Body {
7979
blocks: mir

compiler/rustc_smir/src/stable_mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct CrateItem(pub(crate) DefId);
6262

6363
impl CrateItem {
6464
pub fn body(&self) -> mir::Body {
65-
with(|cx| cx.mir_body(self))
65+
with(|cx| cx.mir_body(self.0))
6666
}
6767
}
6868

@@ -113,7 +113,7 @@ pub trait Context {
113113
fn entry_fn(&mut self) -> Option<CrateItem>;
114114
/// Retrieve all items of the local crate that have a MIR associated with them.
115115
fn all_local_items(&mut self) -> CrateItems;
116-
fn mir_body(&mut self, item: &CrateItem) -> mir::Body;
116+
fn mir_body(&mut self, item: DefId) -> mir::Body;
117117
fn all_trait_decls(&mut self) -> TraitDecls;
118118
fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl;
119119
fn all_trait_impls(&mut self) -> ImplTraitDecls;

compiler/rustc_smir/src/stable_mir/ty.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use super::{mir::Mutability, mir::Safety, with, AllocId, DefId};
1+
use super::{
2+
mir::Safety,
3+
mir::{Body, Mutability},
4+
with, AllocId, DefId,
5+
};
26
use crate::rustc_internal::Opaque;
37

48
#[derive(Copy, Clone, Debug)]
@@ -95,6 +99,12 @@ pub struct ForeignDef(pub(crate) DefId);
9599
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
96100
pub struct FnDef(pub(crate) DefId);
97101

102+
impl FnDef {
103+
pub fn body(&self) -> Body {
104+
with(|ctx| ctx.mir_body(self.0))
105+
}
106+
}
107+
98108
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
99109
pub struct ClosureDef(pub(crate) DefId);
100110

0 commit comments

Comments
 (0)