Skip to content

Commit dca7207

Browse files
committed
use ccx
1 parent 514e4a9 commit dca7207

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

compiler/rustc_mir_transform/src/promote_consts_local_arrays.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl<'tcx> MirPass<'tcx> for PromoteArraysOpt<'tcx> {
6060

6161
#[instrument(level = "trace", skip(self, tcx, body))]
6262
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
63+
use hir::ConstContext::{Const, Static};
6364
debug!("running on body: {:?}", body.source.def_id());
6465
// There's not really any point in promoting errorful MIR.
6566
//
@@ -72,16 +73,12 @@ impl<'tcx> MirPass<'tcx> for PromoteArraysOpt<'tcx> {
7273
return;
7374
}
7475

76+
let ccx = ConstCx::new(tcx, body);
7577
// Ignore static/const items. Already processed by PromoteTemps
76-
if let Some(ctx) = tcx.hir().body_const_context(body.source.def_id()) {
77-
use hir::ConstContext::*;
78-
match ctx {
79-
Static(_) | Const { inline: _ } => return,
80-
_ => {}
81-
}
78+
if let Some(Static(_) | Const { inline: _ }) = ccx.const_kind {
79+
return;
8280
}
8381

84-
let ccx = ConstCx::new(tcx, body);
8582
let (mut temps, mut all_candidates, already_promoted) = collect_temps_and_candidates(&ccx);
8683

8784
let promotable_candidates = validate_candidates(&ccx, &mut temps, &mut all_candidates);

tests/mir-opt/const_array_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
struct F32x8([f32; 8]);
66

77
// EMIT_MIR const_array_locals.main.PromoteArraysOpt.diff
8-
// CHECK-LABEL: fn main() -> () {
8+
// CHECK-LABEL: fn main(
99
#[rustfmt::skip]
1010
pub fn main() {
1111
// CHECK: let [[array_lit:_.*]]: [i32; 32];

0 commit comments

Comments
 (0)