Rollup merge of #115749 - oli-obk:smir_consts, r=compiler-errors

Allow loading the SMIR for constants and statics

cc https://github.com/rust-lang/project-stable-mir/issues/34

before this PR we were ICEing when trying to access the SMIR of anything other than functions
This commit is contained in:
Matthias Krüger 2023-09-11 21:16:23 +02:00 committed by GitHub
commit 2a087be735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -84,7 +84,7 @@ impl<'tcx> Context for Tables<'tcx> {
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]