about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-09-13 08:40:43 -0400
committerWesley Wiser <wwiser@gmail.com>2019-09-27 20:11:12 -0400
commit15d2b7ae8122c19c4c4133a6206f90f676a60dff (patch)
treeb36698a60007d65d71253110994635a85ec0b398 /src
parentfadfd92c2f27fbaf3473f952fb9a35b8fc20693a (diff)
downloadrust-15d2b7ae8122c19c4c4133a6206f90f676a60dff.tar.gz
rust-15d2b7ae8122c19c4c4133a6206f90f676a60dff.zip
Respond to code review feedback and fix tidy
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/interpret/eval_context.rs4
-rw-r--r--src/librustc_mir/interpret/step.rs2
-rw-r--r--src/librustc_mir/transform/const_prop.rs33
-rw-r--r--src/test/ui/consts/const-prop-read-static-in-const.rs12
-rw-r--r--src/test/ui/consts/const-prop-read-static-in-const.stderr6
5 files changed, 42 insertions, 15 deletions
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 7ca14b51740..bc7a5a1a7c3 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -134,7 +134,9 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
     pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> {
         match self.value {
             LocalValue::Dead => throw_unsup!(DeadLocal),
-            LocalValue::Uninitialized => throw_unsup!(UninitializedLocal),
+            LocalValue::Uninitialized =>
+                // this is reachable from ConstProp
+                throw_unsup!(UninitializedLocal),
             LocalValue::Live(val) => Ok(val),
         }
     }
diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs
index 0aa6f5174c1..bdc44471b64 100644
--- a/src/librustc_mir/interpret/step.rs
+++ b/src/librustc_mir/interpret/step.rs
@@ -245,7 +245,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                 // report those as uninitialized for now.
                 if let Place {
                     base: PlaceBase::Local(local),
-                    projection: None
+                    projection: box []
                 } = place {
                     let alive =
                         if let LocalValue::Live(_) = self.frame().locals[*local].value {
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 7049fee5f8d..b00c15ca501 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -569,11 +569,15 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
                     base: PlaceBase::Local(local),
                     projection: box [],
                 } = *place {
-                    if let Some(value) = self.const_prop(rval, place_layout, statement.source_info, place) {
+                    if let Some(value) = self.const_prop(rval,
+                                                         place_layout,
+                                                         statement.source_info,
+                                                         place) {
                         trace!("checking whether {:?} can be stored to {:?}", value, local);
                         if self.can_const_prop[local] {
                             trace!("storing {:?} to {:?}", value, local);
-                            assert!(self.get_const(local).is_none() || self.get_const(local) == Some(value));
+                            assert!(self.get_const(local).is_none() ||
+                                    self.get_const(local) == Some(value));
                             self.set_const(local, value);
 
                             if self.should_const_prop() {
@@ -587,19 +591,22 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
                     }
                 }
             }
-        } else if let StatementKind::StorageLive(local) = statement.kind {
-            if self.can_const_prop[local] {
-                let frame = self.ecx.frame_mut();
-
-                frame.locals[local].value = LocalValue::Uninitialized;
-            }
-        } else if let StatementKind::StorageDead(local) = statement.kind {
-            if self.can_const_prop[local] {
-                let frame = self.ecx.frame_mut();
-
-                frame.locals[local].value = LocalValue::Dead;
+        } else {
+            match statement.kind {
+                StatementKind::StorageLive(local) |
+                StatementKind::StorageDead(local) if self.can_const_prop[local] => {
+                    let frame = self.ecx.frame_mut();
+                    frame.locals[local].value =
+                        if let StatementKind::StorageLive(_) = statement.kind {
+                            LocalValue::Uninitialized
+                        } else {
+                            LocalValue::Dead
+                        };
+                }
+                _ => {}
             }
         }
+
         self.super_statement(statement, location);
     }
 
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.rs b/src/test/ui/consts/const-prop-read-static-in-const.rs
new file mode 100644
index 00000000000..7504fd52595
--- /dev/null
+++ b/src/test/ui/consts/const-prop-read-static-in-const.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// run-pass
+
+#![allow(dead_code)]
+
+const TEST: u8 = MY_STATIC;
+//~^ skipping const checks
+
+static MY_STATIC: u8 = 4;
+
+fn main() {
+}
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.stderr b/src/test/ui/consts/const-prop-read-static-in-const.stderr
new file mode 100644
index 00000000000..bbd5b12ed7d
--- /dev/null
+++ b/src/test/ui/consts/const-prop-read-static-in-const.stderr
@@ -0,0 +1,6 @@
+warning: skipping const checks
+  --> $DIR/const-prop-read-static-in-const.rs:6:18
+   |
+LL | const TEST: u8 = MY_STATIC;
+   |                  ^^^^^^^^^
+