]> git.lizzy.rs Git - rust.git/commitdiff
Change control flow error to delay span bug
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Sat, 9 Nov 2019 17:07:13 +0000 (09:07 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 13 Nov 2019 18:44:14 +0000 (10:44 -0800)
src/librustc_mir/transform/check_consts/validation.rs
src/librustc_mir/transform/qualify_consts.rs
src/librustc_passes/check_const.rs

index 244d434a51eabc8c96c2a37e697b831a698dfab4..88f16299dc0f7cf3c482d8857570fc1a81dbce64 100644 (file)
@@ -461,7 +461,14 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
                 self.super_statement(statement, location);
             }
             StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
-                self.check_op(ops::IfOrMatch);
+                // 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",
+                    );
+                }
             }
             // FIXME(eddyb) should these really do nothing?
             StatementKind::FakeRead(..) |
index 39720af4cb5d60f26053b1055a99a69981036a7f..255e71db89d555325ea7a6c1217951db6bc90b87 100644 (file)
@@ -723,8 +723,12 @@ fn check_const(&mut self) -> u8 {
                     bb = target;
                 }
                 _ => {
-                    self.not_const(ops::Loop);
-                    validator.check_op(ops::Loop);
+                    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",
+                        );
+                    }
                     break;
                 }
             }
@@ -1253,7 +1257,12 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
                 self.super_statement(statement, location);
             }
             StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
-                self.not_const(ops::IfOrMatch);
+                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",
+                    );
+                }
             }
             // FIXME(eddyb) should these really do nothing?
             StatementKind::FakeRead(..) |
index ff0de4a73b7919c3e17b0d51f834b692f1fa178e..3263ee512a950c57ebcec9cde9374a0fc5354706 100644 (file)
@@ -60,10 +60,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: DefId) {
-    if tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
-        return;
-    }
-
     let mut vis = CheckConstVisitor::new(tcx);
     tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis.as_deep_visitor());
 }
@@ -93,6 +89,11 @@ fn new(tcx: TyCtxt<'tcx>) -> Self {
 
     /// Emits an error when an unsupported expression is found in a const context.
     fn const_check_violated(&self, bad_op: &str, span: Span) {
+        if self.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
+            self.sess.span_warn(span, "skipping const checks");
+            return;
+        }
+
         let const_kind = self.const_kind
             .expect("`const_check_violated` may only be called inside a const context");