Skip to content

Commit 039fc48

Browse files
committed
Respond to code review feedback and fix tidy
1 parent fe323d4 commit 039fc48

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

src/librustc_mir/interpret/eval_context.rs

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

src/librustc_mir/transform/const_prop.rs

+20-13
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
3+
#![allow(dead_code)]
4+
5+
const TEST: u8 = MY_STATIC;
6+
//~^ skipping const checks
7+
//~| ERROR any use of this value will cause an error
8+
9+
static MY_STATIC: u8 = 4;
10+
11+
fn main() {
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: skipping const checks
2+
--> $DIR/const-prop-read-static-in-const.rs:5:18
3+
|
4+
LL | const TEST: u8 = MY_STATIC;
5+
| ^^^^^^^^^
6+
7+
error: any use of this value will cause an error
8+
--> $DIR/const-prop-read-static-in-const.rs:5:18
9+
|
10+
LL | const TEST: u8 = MY_STATIC;
11+
| -----------------^^^^^^^^^-
12+
| |
13+
| tried to read from a static during const evaluation
14+
|
15+
= note: `#[deny(const_err)]` on by default
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)