Skip to content

Commit baa9efb

Browse files
committed
rustc_mir: follow FalseUnwind's real_target edge in qualify_consts.
1 parent 6907005 commit baa9efb

12 files changed

+58
-28
lines changed

src/librustc_mir/transform/qualify_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
890890

891891
let target = match body[bb].terminator().kind {
892892
TerminatorKind::Goto { target } |
893+
TerminatorKind::FalseUnwind { real_target: target, .. } |
893894
TerminatorKind::Drop { target, .. } |
894895
TerminatorKind::DropAndReplace { target, .. } |
895896
TerminatorKind::Assert { target, .. } |
@@ -908,8 +909,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
908909
TerminatorKind::GeneratorDrop |
909910
TerminatorKind::Yield { .. } |
910911
TerminatorKind::Unreachable |
911-
TerminatorKind::FalseEdges { .. } |
912-
TerminatorKind::FalseUnwind { .. } => None,
912+
TerminatorKind::FalseEdges { .. } => None,
913913

914914
TerminatorKind::Return => {
915915
break;

src/test/compile-fail/const-fn-error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fn f(x: usize) -> usize {
66
let mut sum = 0;
77
for i in 0..x {
88
//~^ ERROR E0015
9+
//~| ERROR E0017
910
//~| ERROR E0019
1011
//~| ERROR E0019
1112
//~| ERROR E0080

src/test/compile-fail/issue-52443.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
fn main() {
22
[(); & { loop { continue } } ]; //~ ERROR mismatched types
33
[(); loop { break }]; //~ ERROR mismatched types
4-
[(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type
5-
//~^ WARN denote infinite loops with
6-
[(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
4+
[(); {while true {break}; 0}];
75
//~^ ERROR constant contains unimplemented expression type
86
//~| ERROR constant contains unimplemented expression type
7+
//~| WARN denote infinite loops with
8+
[(); { for _ in 0usize.. {}; 0}];
9+
//~^ ERROR calls in constants are limited to constant functions
10+
//~| ERROR references in constants may only refer to immutable values
11+
//~| ERROR constant contains unimplemented expression type
12+
//~| ERROR constant contains unimplemented expression type
913
//~| ERROR evaluation of constant value failed
1014
}

src/test/ui/consts/const-eval/infinite_loop.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ fn main() {
44
let _ = [(); {
55
//~^ WARNING Constant evaluating a complex constant, this might take some time
66
let mut n = 113383; // #20 in https://oeis.org/A006884
7-
while n != 0 { //~ ERROR constant contains unimplemented expression type
7+
while n != 0 {
8+
//~^ ERROR constant contains unimplemented expression type
9+
//~| ERROR constant contains unimplemented expression type
810
n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
911
//~^ ERROR evaluation of constant value failed
1012
}

src/test/ui/consts/const-eval/infinite_loop.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/infinite_loop.rs:7:15
3+
|
4+
LL | while n != 0 {
5+
| ^^^^^^
6+
17
error[E0019]: constant contains unimplemented expression type
28
--> $DIR/infinite_loop.rs:7:9
39
|
410
LL | / while n != 0 {
11+
LL | |
12+
LL | |
513
LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
614
LL | |
715
LL | | }
@@ -21,12 +29,12 @@ LL | | }];
2129
| |_____^
2230

2331
error[E0080]: evaluation of constant value failed
24-
--> $DIR/infinite_loop.rs:8:20
32+
--> $DIR/infinite_loop.rs:10:20
2533
|
2634
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
2735
| ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
2836

29-
error: aborting due to 2 previous errors
37+
error: aborting due to 3 previous errors
3038

3139
Some errors have detailed explanations: E0019, E0080.
3240
For more information about an error, try `rustc --explain E0019`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn main() {
2-
[(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type
3-
//~^ ERROR it is undefined behavior to use this value
2+
[(); { &loop { break } as *const _ as usize } ];
3+
//~^ ERROR casting pointers to integers in constants is unstable
4+
//~| ERROR it is undefined behavior to use this value
45
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0019]: constant contains unimplemented expression type
2-
--> $DIR/issue-52442.rs:2:14
1+
error[E0658]: casting pointers to integers in constants is unstable
2+
--> $DIR/issue-52442.rs:2:13
33
|
44
LL | [(); { &loop { break } as *const _ as usize } ];
5-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
8+
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
69

710
error[E0080]: it is undefined behavior to use this value
811
--> $DIR/issue-52442.rs:2:11
@@ -14,5 +17,5 @@ LL | [(); { &loop { break } as *const _ as usize } ];
1417

1518
error: aborting due to 2 previous errors
1619

17-
Some errors have detailed explanations: E0019, E0080.
18-
For more information about an error, try `rustc --explain E0019`.
20+
Some errors have detailed explanations: E0080, E0658.
21+
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/issue-52475.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ fn main() {
33
//~^ WARNING Constant evaluating a complex constant, this might take some time
44
let mut x = &0;
55
let mut n = 0;
6-
while n < 5 { //~ ERROR constant contains unimplemented expression type
6+
while n < 5 {
7+
//~^ ERROR constant contains unimplemented expression type
8+
//~| ERROR constant contains unimplemented expression type
79
n = (n + 1) % 5; //~ ERROR evaluation of constant value failed
810
x = &0; // Materialize a new AllocId
911
}

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/issue-52475.rs:6:15
3+
|
4+
LL | while n < 5 {
5+
| ^^^^^
6+
17
error[E0019]: constant contains unimplemented expression type
28
--> $DIR/issue-52475.rs:6:9
39
|
410
LL | / while n < 5 {
11+
LL | |
12+
LL | |
513
LL | | n = (n + 1) % 5;
614
LL | | x = &0; // Materialize a new AllocId
715
LL | | }
@@ -21,12 +29,12 @@ LL | | }];
2129
| |_____^
2230

2331
error[E0080]: evaluation of constant value failed
24-
--> $DIR/issue-52475.rs:7:17
32+
--> $DIR/issue-52475.rs:9:17
2533
|
2634
LL | n = (n + 1) % 5;
2735
| ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
2836

29-
error: aborting due to 2 previous errors
37+
error: aborting due to 3 previous errors
3038

3139
Some errors have detailed explanations: E0019, E0080.
3240
For more information about an error, try `rustc --explain E0019`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-pass
2+
3+
// Tests that `loop`s unconditionally-broken-from are allowed in constants.
4+
5+
const FOO: () = loop { break; };
6+
7+
fn main() {
8+
[FOO; { let x; loop { x = 5; break; } x }];
9+
}
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// run-pass
2+
13
// Using labeled break in a while loop has caused an illegal instruction being
24
// generated, and an ICE later.
35
//
46
// See https://github.com/rust-lang/rust/issues/51350 for more information.
57

68
const CRASH: () = 'a: while break 'a {};
7-
//~^ ERROR constant contains unimplemented expression type
89

910
fn main() {}

src/test/ui/consts/const-labeled-break.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)