]> git.lizzy.rs Git - rust.git/commitdiff
Bless back-compat breakages
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 7 Nov 2019 01:45:10 +0000 (17:45 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 13 Nov 2019 18:44:14 +0000 (10:44 -0800)
This PR BREAKS CODE THAT WAS ACCEPTED ON STABLE. It's arguably a bug
that this was accepted in the first place, but here we are. See #62272
for more info.

src/test/ui/consts/const-eval/issue-52442.rs
src/test/ui/consts/const-eval/issue-52442.stderr
src/test/ui/consts/const-eval/issue-62272.rs
src/test/ui/consts/const-eval/issue-62272.stderr [new file with mode: 0644]
src/test/ui/consts/const-labeled-break.rs
src/test/ui/consts/const-labeled-break.stderr [new file with mode: 0644]

index ea24578c7dd0cfd28f6937987db69918d647e143..d820c7051612456a128f108dfcdc0aeaa26b00eb 100644 (file)
@@ -1,5 +1,6 @@
 fn main() {
     [();  { &loop { break } as *const _ as usize } ];
     //~^ ERROR casting pointers to integers in constants is unstable
+    //~| ERROR `loop` is not allowed in a `const`
     //~| ERROR evaluation of constant value failed
 }
index 5bd4979bdb33cf4b15a581195376b8ed04cbee92..fa2272f8d634df64d97f83ad3d57631e29734e4b 100644 (file)
@@ -1,3 +1,9 @@
+error[E0744]: `loop` is not allowed in a `const`
+  --> $DIR/issue-52442.rs:2:14
+   |
+LL |     [();  { &loop { break } as *const _ as usize } ];
+   |              ^^^^^^^^^^^^^^
+
 error[E0658]: casting pointers to integers in constants is unstable
   --> $DIR/issue-52442.rs:2:13
    |
@@ -13,7 +19,7 @@ error[E0080]: evaluation of constant value failed
 LL |     [();  { &loop { break } as *const _ as usize } ];
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0080, E0658.
+Some errors have detailed explanations: E0080, E0658, E0744.
 For more information about an error, try `rustc --explain E0080`.
index ad8589c73788cfc8dc6b2f463fee69185eedaa0d..19abd91252db9725abc28b2a6e80bd58383b9625 100644 (file)
@@ -1,9 +1,11 @@
-// run-pass
+// `loop`s unconditionally-broken-from used to be allowed in constants, but are now forbidden by
+// the HIR const-checker.
+//
+// See https://github.com/rust-lang/rust/pull/66170 and
+// https://github.com/rust-lang/rust/issues/62272.
 
-// Tests that `loop`s unconditionally-broken-from are allowed in constants.
-
-const FOO: () = loop { break; };
+const FOO: () = loop { break; }; //~ ERROR `loop` is not allowed in a `const`
 
 fn main() {
-    [FOO; { let x; loop { x = 5; break; } x }];
+    [FOO; { let x; loop { x = 5; break; } x }]; //~ ERROR `loop` is not allowed in a `const`
 }
diff --git a/src/test/ui/consts/const-eval/issue-62272.stderr b/src/test/ui/consts/const-eval/issue-62272.stderr
new file mode 100644 (file)
index 0000000..573d04f
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0744]: `loop` is not allowed in a `const`
+  --> $DIR/issue-62272.rs:7:17
+   |
+LL | const FOO: () = loop { break; };
+   |                 ^^^^^^^^^^^^^^^
+
+error[E0744]: `loop` is not allowed in a `const`
+  --> $DIR/issue-62272.rs:10:20
+   |
+LL |     [FOO; { let x; loop { x = 5; break; } x }];
+   |                    ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0744`.
index 7cdbb22f9245960bcdf243e676c9c7c14a1a7da6..45e3cf438888e64344cd353c8e17054d09416e9d 100644 (file)
@@ -1,10 +1,12 @@
-// build-pass
-
 // Using labeled break in a while loop has caused an illegal instruction being
 // generated, and an ICE later.
 //
 // See https://github.com/rust-lang/rust/issues/51350 for more information.
+//
+// It is now forbidden by the HIR const-checker.
+//
+// See https://github.com/rust-lang/rust/pull/66170.
 
-const CRASH: () = 'a: while break 'a {};
+const CRASH: () = 'a: while break 'a {}; //~ ERROR `while` is not allowed in a `const`
 
 fn main() {}
diff --git a/src/test/ui/consts/const-labeled-break.stderr b/src/test/ui/consts/const-labeled-break.stderr
new file mode 100644 (file)
index 0000000..ec32386
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0744]: `while` is not allowed in a `const`
+  --> $DIR/const-labeled-break.rs:10:19
+   |
+LL | const CRASH: () = 'a: while break 'a {};
+   |                   ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0744`.