about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-12 22:46:40 +0200
committerGitHub <noreply@github.com>2019-07-12 22:46:40 +0200
commit9ffeb26e0b0491fe165911550c63795b76503aa5 (patch)
treea446895a1b1e84eeeed0679a7ed65b6ce69ed324
parent74ac956fad4481909885811d1c38beaf40042e3e (diff)
parentbaa9efb1786ccf62b3808375af65d6ae6ac56e98 (diff)
downloadrust-9ffeb26e0b0491fe165911550c63795b76503aa5.tar.gz
rust-9ffeb26e0b0491fe165911550c63795b76503aa5.zip
Rollup merge of #62274 - eddyb:const-false-unwind, r=pnkfelix
rustc_mir: follow FalseUnwind's real_target edge in qualify_consts.

As far as I can tell, this was accidentally omitted from #47802.
Fixes #62272.

r? @matthewjasper or @nikomatsakis
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs4
-rw-r--r--src/test/compile-fail/const-fn-error.rs1
-rw-r--r--src/test/compile-fail/issue-52443.rs10
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.rs4
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.stderr12
-rw-r--r--src/test/ui/consts/const-eval/issue-52442.rs5
-rw-r--r--src/test/ui/consts/const-eval/issue-52442.stderr13
-rw-r--r--src/test/ui/consts/const-eval/issue-52475.rs4
-rw-r--r--src/test/ui/consts/const-eval/issue-52475.stderr12
-rw-r--r--src/test/ui/consts/const-eval/issue-62272.rs9
-rw-r--r--src/test/ui/consts/const-labeled-break.rs3
-rw-r--r--src/test/ui/consts/const-labeled-break.stderr9
12 files changed, 58 insertions, 28 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index 1fa539f8a2a..21b8f06d089 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 87a9cf9490d..1de23f2a5e9 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 a993d811d32..28d9937b5e8 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 a2a45af7cb0..8fa5b0a961f 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 3a7da9ff2c8..68e7fdb1251 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 fadcde528d8..2989b200b2f 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 e9afec5766a..88c94d917fe 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 aafdd5fe617..b42249e57fa 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 7a52a38d767..1e83cbcff2b 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 00000000000..ad8589c7378
--- /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 512ad9427ea..36e308ade9c 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 2009e922355..00000000000
--- 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`.