Skip to content

Commit bc5ba5d

Browse files
Bless back-compat breakages
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 rust-lang#62272 for more info.
1 parent bf80513 commit bc5ba5d

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn main() {
22
[(); { &loop { break } as *const _ as usize } ];
33
//~^ ERROR casting pointers to integers in constants is unstable
4+
//~| ERROR `loop` is not allowed in a `const`
45
//~| ERROR evaluation of constant value failed
56
}

src/test/ui/consts/const-eval/issue-52442.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0744]: `loop` is not allowed in a `const`
2+
--> $DIR/issue-52442.rs:2:14
3+
|
4+
LL | [(); { &loop { break } as *const _ as usize } ];
5+
| ^^^^^^^^^^^^^^
6+
17
error[E0658]: casting pointers to integers in constants is unstable
28
--> $DIR/issue-52442.rs:2:13
39
|
@@ -13,7 +19,7 @@ error[E0080]: evaluation of constant value failed
1319
LL | [(); { &loop { break } as *const _ as usize } ];
1420
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
1521

16-
error: aborting due to 2 previous errors
22+
error: aborting due to 3 previous errors
1723

18-
Some errors have detailed explanations: E0080, E0658.
24+
Some errors have detailed explanations: E0080, E0658, E0744.
1925
For more information about an error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// run-pass
1+
// `loop`s unconditionally-broken-from used to be allowed in constants, but are now forbidden by
2+
// the HIR const-checker.
3+
//
4+
// See https://github.com/rust-lang/rust/pull/66170 and
5+
// https://github.com/rust-lang/rust/issues/62272.
26

3-
// Tests that `loop`s unconditionally-broken-from are allowed in constants.
4-
5-
const FOO: () = loop { break; };
7+
const FOO: () = loop { break; }; //~ ERROR `loop` is not allowed in a `const`
68

79
fn main() {
8-
[FOO; { let x; loop { x = 5; break; } x }];
10+
[FOO; { let x; loop { x = 5; break; } x }]; //~ ERROR `loop` is not allowed in a `const`
911
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0744]: `loop` is not allowed in a `const`
2+
--> $DIR/issue-62272.rs:7:17
3+
|
4+
LL | const FOO: () = loop { break; };
5+
| ^^^^^^^^^^^^^^^
6+
7+
error[E0744]: `loop` is not allowed in a `const`
8+
--> $DIR/issue-62272.rs:10:20
9+
|
10+
LL | [FOO; { let x; loop { x = 5; break; } x }];
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0744`.
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// build-pass
2-
31
// Using labeled break in a while loop has caused an illegal instruction being
42
// generated, and an ICE later.
53
//
64
// See https://github.com/rust-lang/rust/issues/51350 for more information.
5+
//
6+
// It is now forbidden by the HIR const-checker.
7+
//
8+
// See https://github.com/rust-lang/rust/pull/66170.
79

8-
const CRASH: () = 'a: while break 'a {};
10+
const CRASH: () = 'a: while break 'a {}; //~ ERROR `while` is not allowed in a `const`
911

1012
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0744]: `while` is not allowed in a `const`
2+
--> $DIR/const-labeled-break.rs:10:19
3+
|
4+
LL | const CRASH: () = 'a: while break 'a {};
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0744`.

0 commit comments

Comments
 (0)