Skip to content

Commit

Permalink
rustc_mir: follow FalseUnwind's real_target edge in qualify_consts.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jul 11, 2019
1 parent 6907005 commit baa9efb
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -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, .. } |
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/const-fn-error.rs
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions 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
}
4 changes: 3 additions & 1 deletion src/test/ui/consts/const-eval/infinite_loop.rs
Expand Up @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions 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 | | }
Expand All @@ -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`.
5 changes: 3 additions & 2 deletions 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
}
13 changes: 8 additions & 5 deletions 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
Expand All @@ -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`.
4 changes: 3 additions & 1 deletion src/test/ui/consts/const-eval/issue-52475.rs
Expand Up @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions 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 | | }
Expand All @@ -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`.
9 changes: 9 additions & 0 deletions 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 }];
}
3 changes: 2 additions & 1 deletion 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() {}
9 changes: 0 additions & 9 deletions src/test/ui/consts/const-labeled-break.stderr

This file was deleted.

0 comments on commit baa9efb

Please sign in to comment.