Skip to content

Commit 15d2b7a

Browse files
committed
Respond to code review feedback and fix tidy
1 parent fadfd92 commit 15d2b7a

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
134134
pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> {
135135
match self.value {
136136
LocalValue::Dead => throw_unsup!(DeadLocal),
137-
LocalValue::Uninitialized => throw_unsup!(UninitializedLocal),
137+
LocalValue::Uninitialized =>
138+
// this is reachable from ConstProp
139+
throw_unsup!(UninitializedLocal),
138140
LocalValue::Live(val) => Ok(val),
139141
}
140142
}

src/librustc_mir/interpret/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
245245
// report those as uninitialized for now.
246246
if let Place {
247247
base: PlaceBase::Local(local),
248-
projection: None
248+
projection: box []
249249
} = place {
250250
let alive =
251251
if let LocalValue::Live(_) = self.frame().locals[*local].value {

src/librustc_mir/transform/const_prop.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,15 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
569569
base: PlaceBase::Local(local),
570570
projection: box [],
571571
} = *place {
572-
if let Some(value) = self.const_prop(rval, place_layout, statement.source_info, place) {
572+
if let Some(value) = self.const_prop(rval,
573+
place_layout,
574+
statement.source_info,
575+
place) {
573576
trace!("checking whether {:?} can be stored to {:?}", value, local);
574577
if self.can_const_prop[local] {
575578
trace!("storing {:?} to {:?}", value, local);
576-
assert!(self.get_const(local).is_none() || self.get_const(local) == Some(value));
579+
assert!(self.get_const(local).is_none() ||
580+
self.get_const(local) == Some(value));
577581
self.set_const(local, value);
578582

579583
if self.should_const_prop() {
@@ -587,19 +591,22 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
587591
}
588592
}
589593
}
590-
} else if let StatementKind::StorageLive(local) = statement.kind {
591-
if self.can_const_prop[local] {
592-
let frame = self.ecx.frame_mut();
593-
594-
frame.locals[local].value = LocalValue::Uninitialized;
595-
}
596-
} else if let StatementKind::StorageDead(local) = statement.kind {
597-
if self.can_const_prop[local] {
598-
let frame = self.ecx.frame_mut();
599-
600-
frame.locals[local].value = LocalValue::Dead;
594+
} else {
595+
match statement.kind {
596+
StatementKind::StorageLive(local) |
597+
StatementKind::StorageDead(local) if self.can_const_prop[local] => {
598+
let frame = self.ecx.frame_mut();
599+
frame.locals[local].value =
600+
if let StatementKind::StorageLive(_) = statement.kind {
601+
LocalValue::Uninitialized
602+
} else {
603+
LocalValue::Dead
604+
};
605+
}
606+
_ => {}
601607
}
602608
}
609+
603610
self.super_statement(statement, location);
604611
}
605612

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
// run-pass
3+
4+
#![allow(dead_code)]
5+
6+
const TEST: u8 = MY_STATIC;
7+
//~^ skipping const checks
8+
9+
static MY_STATIC: u8 = 4;
10+
11+
fn main() {
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: skipping const checks
2+
--> $DIR/const-prop-read-static-in-const.rs:6:18
3+
|
4+
LL | const TEST: u8 = MY_STATIC;
5+
| ^^^^^^^^^
6+

0 commit comments

Comments
 (0)