diff --git a/src/test/ui/consts/const-eval/issue-52442.rs b/src/test/ui/consts/const-eval/issue-52442.rs index ea24578c7dd..d820c705161 100644 --- a/src/test/ui/consts/const-eval/issue-52442.rs +++ b/src/test/ui/consts/const-eval/issue-52442.rs @@ -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 } diff --git a/src/test/ui/consts/const-eval/issue-52442.stderr b/src/test/ui/consts/const-eval/issue-52442.stderr index 5bd4979bdb3..fa2272f8d63 100644 --- a/src/test/ui/consts/const-eval/issue-52442.stderr +++ b/src/test/ui/consts/const-eval/issue-52442.stderr @@ -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`. diff --git a/src/test/ui/consts/const-eval/issue-62272.rs b/src/test/ui/consts/const-eval/issue-62272.rs index ad8589c7378..19abd91252d 100644 --- a/src/test/ui/consts/const-eval/issue-62272.rs +++ b/src/test/ui/consts/const-eval/issue-62272.rs @@ -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 index 00000000000..573d04f5e47 --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-62272.stderr @@ -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`. diff --git a/src/test/ui/consts/const-labeled-break.rs b/src/test/ui/consts/const-labeled-break.rs index 7cdbb22f924..45e3cf43888 100644 --- a/src/test/ui/consts/const-labeled-break.rs +++ b/src/test/ui/consts/const-labeled-break.rs @@ -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 index 00000000000..ec32386439f --- /dev/null +++ b/src/test/ui/consts/const-labeled-break.stderr @@ -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`.