]> git.lizzy.rs Git - rust.git/commitdiff
Replace the ICEing on const fn loops with an error
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 19 Nov 2018 09:40:09 +0000 (10:40 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 19 Nov 2018 09:40:09 +0000 (10:40 +0100)
src/librustc_mir/transform/qualify_min_const_fn.rs
src/test/ui/consts/min_const_fn/loop_ice.rs [new file with mode: 0644]
src/test/ui/consts/min_const_fn/loop_ice.stderr [new file with mode: 0644]

index ed13063cfdf1700d3abd4a64eaff14a5cd200f59..958e5efe3ec74e9b3ffde0f33324917fdd1d38ff 100644 (file)
@@ -365,10 +365,8 @@ fn check_terminator(
             cleanup: _,
         } => check_operand(tcx, mir, cond, span),
 
-        | TerminatorKind::FalseUnwind { .. } => span_bug!(
-            terminator.source_info.span,
-            "min_const_fn encountered `{:#?}`",
-            terminator
-        ),
+        TerminatorKind::FalseUnwind { .. } => {
+            Err((span, "loops are not allowed in const fn".into()))
+        },
     }
 }
diff --git a/src/test/ui/consts/min_const_fn/loop_ice.rs b/src/test/ui/consts/min_const_fn/loop_ice.rs
new file mode 100644 (file)
index 0000000..4278a8e
--- /dev/null
@@ -0,0 +1,5 @@
+const fn foo() {
+    loop {} //~ ERROR loops are not allowed in const fn
+}
+
+fn main() {}
diff --git a/src/test/ui/consts/min_const_fn/loop_ice.stderr b/src/test/ui/consts/min_const_fn/loop_ice.stderr
new file mode 100644 (file)
index 0000000..1424cea
--- /dev/null
@@ -0,0 +1,8 @@
+error: loops are not allowed in const fn
+  --> $DIR/loop_ice.rs:2:5
+   |
+LL |     loop {} //~ ERROR loops are not allowed in const fn
+   |     ^^^^^^^
+
+error: aborting due to previous error
+