Skip to content

Commit 2a087be

Browse files
authored
Rollup merge of rust-lang#115749 - oli-obk:smir_consts, r=compiler-errors
Allow loading the SMIR for constants and statics cc rust-lang/project-stable-mir#34 before this PR we were ICEing when trying to access the SMIR of anything other than functions
2 parents c943ec2 + c2e7900 commit 2a087be

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> Context for Tables<'tcx> {
8484

8585
fn mir_body(&mut self, item: stable_mir::DefId) -> stable_mir::mir::Body {
8686
let def_id = self[item];
87-
let mir = self.tcx.optimized_mir(def_id);
87+
let mir = self.tcx.instance_mir(ty::InstanceDef::Item(def_id));
8888
stable_mir::mir::Body {
8989
blocks: mir
9090
.basic_blocks

tests/ui-fulldeps/stable-mir/crate-info.rs

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
154154
}
155155
}
156156

157+
let foo_const = get_item(tcx, &items, (DefKind::Const, "FOO")).unwrap();
158+
// Ensure we don't panic trying to get the body of a constant.
159+
foo_const.body();
160+
157161
ControlFlow::Continue(())
158162
}
159163

@@ -191,6 +195,8 @@ fn generate_input(path: &str) -> std::io::Result<()> {
191195
write!(
192196
file,
193197
r#"
198+
pub const FOO: u32 = 1 + 2;
199+
194200
fn generic<T, const U: usize>(t: T) -> [(); U] {{
195201
_ = t;
196202
[(); U]

0 commit comments

Comments
 (0)