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:
commit
2a087be735
@ -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
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user