Skip to content

Commit 202fbed

Browse files
committed
Allow fetching the SMIR body of FnDefs
1 parent 98d26d9 commit 202fbed

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
@@ -78,8 +78,8 @@ impl<'tcx> Context for Tables<'tcx> {
7878
impl_trait.stable(self)
7979
}
8080

81-
fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body {
82-
let def_id = self[item.0];
81+
fn mir_body(&mut self, item: stable_mir::DefId) -> stable_mir::mir::Body {
82+
let def_id = self[item];
8383
let mir = self.tcx.optimized_mir(def_id);
8484
stable_mir::mir::Body {
8585
blocks: mir

compiler/rustc_smir/src/stable_mir/mod.rs

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

8888
impl CrateItem {
8989
pub fn body(&self) -> mir::Body {
90-
with(|cx| cx.mir_body(self))
90+
with(|cx| cx.mir_body(self.0))
9191
}
9292
}
9393

@@ -138,7 +138,7 @@ pub trait Context {
138138
fn entry_fn(&mut self) -> Option<CrateItem>;
139139
/// Retrieve all items of the local crate that have a MIR associated with them.
140140
fn all_local_items(&mut self) -> CrateItems;
141-
fn mir_body(&mut self, item: &CrateItem) -> mir::Body;
141+
fn mir_body(&mut self, item: DefId) -> mir::Body;
142142
fn all_trait_decls(&mut self) -> TraitDecls;
143143
fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl;
144144
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)