about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2019-11-10 10:39:27 -0800
committerDylan MacKenzie <ecstaticmorse@gmail.com>2019-11-15 10:33:52 -0800
commit752776699357be34e7819ffb235438df7ccf1a9a (patch)
tree6769a2c4a524ea0417f7c126e54a7e333fe37a02
parent6d4e2042f9dae20266292c45b2789962873b1d01 (diff)
downloadrust-752776699357be34e7819ffb235438df7ccf1a9a.tar.gz
rust-752776699357be34e7819ffb235438df7ccf1a9a.zip
Move `delay_span_bug` into `emit_error` for if/loop
-rw-r--r--src/librustc_mir/transform/check_consts/ops.rs20
-rw-r--r--src/librustc_mir/transform/check_consts/validation.rs21
2 files changed, 22 insertions, 19 deletions
diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs
index 303c3984f7c..80f2925193a 100644
--- a/src/librustc_mir/transform/check_consts/ops.rs
+++ b/src/librustc_mir/transform/check_consts/ops.rs
@@ -138,7 +138,15 @@ impl NonConstOp for HeapAllocation {
 
 #[derive(Debug)]
 pub struct IfOrMatch;
-impl NonConstOp for IfOrMatch {}
+impl NonConstOp for IfOrMatch {
+    fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
+        // This should be caught by the HIR const-checker.
+        item.tcx.sess.delay_span_bug(
+            span,
+            "complex control flow is forbidden in a const context",
+        );
+    }
+}
 
 #[derive(Debug)]
 pub struct LiveDrop;
@@ -154,7 +162,15 @@ impl NonConstOp for LiveDrop {
 
 #[derive(Debug)]
 pub struct Loop;
-impl NonConstOp for Loop {}
+impl NonConstOp for Loop {
+    fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
+        // This should be caught by the HIR const-checker.
+        item.tcx.sess.delay_span_bug(
+            span,
+            "complex control flow is forbidden in a const context",
+        );
+    }
+}
 
 #[derive(Debug)]
 pub struct MutBorrow(pub BorrowKind);
diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs
index 6687618b748..52481a89e2f 100644
--- a/src/librustc_mir/transform/check_consts/validation.rs
+++ b/src/librustc_mir/transform/check_consts/validation.rs
@@ -245,16 +245,10 @@ impl Validator<'a, 'mir, 'tcx> {
 
         check_short_circuiting_in_const_local(self.item);
 
-        // FIXME: give a span for the loop
         if body.is_cfg_cyclic() {
-            // FIXME: make this the `emit_error` impl of `ops::Loop` once the const
-            // checker is no longer run in compatability mode.
-            if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
-                self.tcx.sess.delay_span_bug(
-                    self.span,
-                    "complex control flow is forbidden in a const context",
-                );
-            }
+            // We can't provide a good span for the error here, but this should be caught by the
+            // HIR const-checker anyways.
+            self.check_op_spanned(ops::Loop, body.span);
         }
 
         self.visit_body(body);
@@ -565,14 +559,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
                 self.super_statement(statement, location);
             }
             StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
-                // FIXME: make this the `emit_error` impl of `ops::IfOrMatch` once the const
-                // checker is no longer run in compatability mode.
-                if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
-                    self.tcx.sess.delay_span_bug(
-                        self.span,
-                        "complex control flow is forbidden in a const context",
-                    );
-                }
+                self.check_op(ops::IfOrMatch);
             }
             // FIXME(eddyb) should these really do nothing?
             StatementKind::FakeRead(..) |