Allow loading the SMIR for constants and statics

This commit is contained in:
Oli Scherer 2023-09-11 08:14:39 +00:00
parent e39976ff89
commit c2e790044c
2 changed files with 7 additions and 1 deletions

View File

@ -84,7 +84,7 @@ fn trait_impl(&mut self, impl_def: &stable_mir::ty::ImplDef) -> stable_mir::ty::
fn mir_body(&mut self, item: stable_mir::DefId) -> stable_mir::mir::Body {
let def_id = self[item];
let mir = self.tcx.optimized_mir(def_id);
let mir = self.tcx.instance_mir(ty::InstanceDef::Item(def_id));
stable_mir::mir::Body {
blocks: mir
.basic_blocks

View File

@ -154,6 +154,10 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
}
}
let foo_const = get_item(tcx, &items, (DefKind::Const, "FOO")).unwrap();
// Ensure we don't panic trying to get the body of a constant.
foo_const.body();
ControlFlow::Continue(())
}
@ -191,6 +195,8 @@ fn generate_input(path: &str) -> std::io::Result<()> {
write!(
file,
r#"
pub const FOO: u32 = 1 + 2;
fn generic<T, const U: usize>(t: T) -> [(); U] {{
_ = t;
[(); U]