]> git.lizzy.rs Git - rust.git/commitdiff
Move `delay_span_bug` into `emit_error` for if/loop
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Sun, 10 Nov 2019 18:39:27 +0000 (10:39 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 15 Nov 2019 18:33:52 +0000 (10:33 -0800)
src/librustc_mir/transform/check_consts/ops.rs
src/librustc_mir/transform/check_consts/validation.rs

index 303c3984f7c0f66dd6e9bc5ee17b2cdce53f723b..80f2925193a8140a87785e1b8b0a273d6b0ab347 100644 (file)
@@ -138,7 +138,15 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
 
 #[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 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
 
 #[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);
index 6687618b7485949854e772a5b3ba90f9d4f715c1..52481a89e2f1d70c42bfc2166df627309cc45573 100644 (file)
@@ -245,16 +245,10 @@ pub fn check_body(&mut self) {
 
         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 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
                 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(..) |