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
}
+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
|
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`.
-// 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`
}
--- /dev/null
+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`.
-// 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() {}
--- /dev/null
+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`.