diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 1fa539f8a2aee..21b8f06d0895f 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -890,6 +890,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { let target = match body[bb].terminator().kind { TerminatorKind::Goto { target } | + TerminatorKind::FalseUnwind { real_target: target, .. } | TerminatorKind::Drop { target, .. } | TerminatorKind::DropAndReplace { target, .. } | TerminatorKind::Assert { target, .. } | @@ -908,8 +909,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } | TerminatorKind::Unreachable | - TerminatorKind::FalseEdges { .. } | - TerminatorKind::FalseUnwind { .. } => None, + TerminatorKind::FalseEdges { .. } => None, TerminatorKind::Return => { break; diff --git a/src/test/compile-fail/const-fn-error.rs b/src/test/compile-fail/const-fn-error.rs index 87a9cf9490d86..1de23f2a5e94f 100644 --- a/src/test/compile-fail/const-fn-error.rs +++ b/src/test/compile-fail/const-fn-error.rs @@ -6,6 +6,7 @@ const fn f(x: usize) -> usize { let mut sum = 0; for i in 0..x { //~^ ERROR E0015 + //~| ERROR E0017 //~| ERROR E0019 //~| ERROR E0019 //~| ERROR E0080 diff --git a/src/test/compile-fail/issue-52443.rs b/src/test/compile-fail/issue-52443.rs index a993d811d327f..28d9937b5e881 100644 --- a/src/test/compile-fail/issue-52443.rs +++ b/src/test/compile-fail/issue-52443.rs @@ -1,10 +1,14 @@ fn main() { [(); & { loop { continue } } ]; //~ ERROR mismatched types [(); loop { break }]; //~ ERROR mismatched types - [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type - //~^ WARN denote infinite loops with - [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions + [(); {while true {break}; 0}]; //~^ ERROR constant contains unimplemented expression type //~| ERROR constant contains unimplemented expression type + //~| WARN denote infinite loops with + [(); { for _ in 0usize.. {}; 0}]; + //~^ ERROR calls in constants are limited to constant functions + //~| ERROR references in constants may only refer to immutable values + //~| ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type //~| ERROR evaluation of constant value failed } diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs index a2a45af7cb086..8fa5b0a961f9f 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -4,7 +4,9 @@ fn main() { let _ = [(); { //~^ WARNING Constant evaluating a complex constant, this might take some time let mut n = 113383; // #20 in https://oeis.org/A006884 - while n != 0 { //~ ERROR constant contains unimplemented expression type + while n != 0 { + //~^ ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; //~^ ERROR evaluation of constant value failed } diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr index 3a7da9ff2c8d8..68e7fdb12517b 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -1,7 +1,15 @@ +error[E0019]: constant contains unimplemented expression type + --> $DIR/infinite_loop.rs:7:15 + | +LL | while n != 0 { + | ^^^^^^ + error[E0019]: constant contains unimplemented expression type --> $DIR/infinite_loop.rs:7:9 | LL | / while n != 0 { +LL | | +LL | | LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; LL | | LL | | } @@ -21,12 +29,12 @@ LL | | }]; | |_____^ error[E0080]: evaluation of constant value failed - --> $DIR/infinite_loop.rs:8:20 + --> $DIR/infinite_loop.rs:10:20 | LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; | ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0019, E0080. For more information about an error, try `rustc --explain E0019`. diff --git a/src/test/ui/consts/const-eval/issue-52442.rs b/src/test/ui/consts/const-eval/issue-52442.rs index fadcde528d86e..2989b200b2fc4 100644 --- a/src/test/ui/consts/const-eval/issue-52442.rs +++ b/src/test/ui/consts/const-eval/issue-52442.rs @@ -1,4 +1,5 @@ fn main() { - [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type - //~^ ERROR it is undefined behavior to use this value + [(); { &loop { break } as *const _ as usize } ]; + //~^ ERROR casting pointers to integers in constants is unstable + //~| ERROR it is undefined behavior to use this value } diff --git a/src/test/ui/consts/const-eval/issue-52442.stderr b/src/test/ui/consts/const-eval/issue-52442.stderr index e9afec5766a0c..88c94d917fe0e 100644 --- a/src/test/ui/consts/const-eval/issue-52442.stderr +++ b/src/test/ui/consts/const-eval/issue-52442.stderr @@ -1,8 +1,11 @@ -error[E0019]: constant contains unimplemented expression type - --> $DIR/issue-52442.rs:2:14 +error[E0658]: casting pointers to integers in constants is unstable + --> $DIR/issue-52442.rs:2:13 | LL | [(); { &loop { break } as *const _ as usize } ]; - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/51910 + = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable error[E0080]: it is undefined behavior to use this value --> $DIR/issue-52442.rs:2:11 @@ -14,5 +17,5 @@ LL | [(); { &loop { break } as *const _ as usize } ]; error: aborting due to 2 previous errors -Some errors have detailed explanations: E0019, E0080. -For more information about an error, try `rustc --explain E0019`. +Some errors have detailed explanations: E0080, E0658. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-52475.rs b/src/test/ui/consts/const-eval/issue-52475.rs index aafdd5fe61782..b42249e57fa9a 100644 --- a/src/test/ui/consts/const-eval/issue-52475.rs +++ b/src/test/ui/consts/const-eval/issue-52475.rs @@ -3,7 +3,9 @@ fn main() { //~^ WARNING Constant evaluating a complex constant, this might take some time let mut x = &0; let mut n = 0; - while n < 5 { //~ ERROR constant contains unimplemented expression type + while n < 5 { + //~^ ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type n = (n + 1) % 5; //~ ERROR evaluation of constant value failed x = &0; // Materialize a new AllocId } diff --git a/src/test/ui/consts/const-eval/issue-52475.stderr b/src/test/ui/consts/const-eval/issue-52475.stderr index 7a52a38d767cc..1e83cbcff2bf1 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -1,7 +1,15 @@ +error[E0019]: constant contains unimplemented expression type + --> $DIR/issue-52475.rs:6:15 + | +LL | while n < 5 { + | ^^^^^ + error[E0019]: constant contains unimplemented expression type --> $DIR/issue-52475.rs:6:9 | LL | / while n < 5 { +LL | | +LL | | LL | | n = (n + 1) % 5; LL | | x = &0; // Materialize a new AllocId LL | | } @@ -21,12 +29,12 @@ LL | | }]; | |_____^ error[E0080]: evaluation of constant value failed - --> $DIR/issue-52475.rs:7:17 + --> $DIR/issue-52475.rs:9:17 | LL | n = (n + 1) % 5; | ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0019, E0080. For more information about an error, try `rustc --explain E0019`. diff --git a/src/test/ui/consts/const-eval/issue-62272.rs b/src/test/ui/consts/const-eval/issue-62272.rs new file mode 100644 index 0000000000000..ad8589c73788c --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-62272.rs @@ -0,0 +1,9 @@ +// run-pass + +// Tests that `loop`s unconditionally-broken-from are allowed in constants. + +const FOO: () = loop { break; }; + +fn main() { + [FOO; { let x; loop { x = 5; break; } x }]; +} diff --git a/src/test/ui/consts/const-labeled-break.rs b/src/test/ui/consts/const-labeled-break.rs index 512ad9427ea54..36e308ade9c54 100644 --- a/src/test/ui/consts/const-labeled-break.rs +++ b/src/test/ui/consts/const-labeled-break.rs @@ -1,9 +1,10 @@ +// run-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. const CRASH: () = 'a: while break 'a {}; -//~^ ERROR constant contains unimplemented expression type fn main() {} diff --git a/src/test/ui/consts/const-labeled-break.stderr b/src/test/ui/consts/const-labeled-break.stderr deleted file mode 100644 index 2009e92235566..0000000000000 --- a/src/test/ui/consts/const-labeled-break.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0019]: constant contains unimplemented expression type - --> $DIR/const-labeled-break.rs:6:19 - | -LL | const CRASH: () = 'a: while break 'a {}; - | ^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0019`.