about summary refs log tree commit diff
path: root/src/test/ui/consts/const-eval
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2019-11-06 12:29:30 -0800
committerDylan MacKenzie <ecstaticmorse@gmail.com>2019-11-13 10:44:14 -0800
commit3ce8ca45d63a65e0c0eaaa4a29f8ce3ccf5350b9 (patch)
tree4ac7348764714836fb5c03797498b6414b16e663 /src/test/ui/consts/const-eval
parent67336bb399deac766faed5e13a032f017c3353b3 (diff)
downloadrust-3ce8ca45d63a65e0c0eaaa4a29f8ce3ccf5350b9.tar.gz
rust-3ce8ca45d63a65e0c0eaaa4a29f8ce3ccf5350b9.zip
Bless const tests with improved diagnostics
Diffstat (limited to 'src/test/ui/consts/const-eval')
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.rs2
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.stderr27
-rw-r--r--src/test/ui/consts/const-eval/issue-52475.rs3
-rw-r--r--src/test/ui/consts/const-eval/issue-52475.stderr19
-rw-r--r--src/test/ui/consts/const-eval/match-test-ptr-null.rs1
-rw-r--r--src/test/ui/consts/const-eval/match-test-ptr-null.stderr18
6 files changed, 59 insertions, 11 deletions
diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs
index 8fa5b0a961f..ee1d588e553 100644
--- a/src/test/ui/consts/const-eval/infinite_loop.rs
+++ b/src/test/ui/consts/const-eval/infinite_loop.rs
@@ -7,8 +7,10 @@ fn main() {
         while n != 0 {
         //~^ ERROR constant contains unimplemented expression type
         //~| ERROR constant contains unimplemented expression type
+        //~| ERROR `while` is not allowed in a `const`
             n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
             //~^ ERROR evaluation of constant value failed
+            //~| ERROR `if` is not allowed in a `const`
         }
         n
     }];
diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr
index 68e7fdb1251..bf5d2c8c328 100644
--- a/src/test/ui/consts/const-eval/infinite_loop.stderr
+++ b/src/test/ui/consts/const-eval/infinite_loop.stderr
@@ -1,3 +1,21 @@
+error[E0744]: `while` is not allowed in a `const`
+  --> $DIR/infinite_loop.rs:7:9
+   |
+LL | /         while n != 0 {
+LL | |
+LL | |
+LL | |
+...  |
+LL | |
+LL | |         }
+   | |_________^
+
+error[E0744]: `if` is not allowed in a `const`
+  --> $DIR/infinite_loop.rs:11:17
+   |
+LL |             n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error[E0019]: constant contains unimplemented expression type
   --> $DIR/infinite_loop.rs:7:15
    |
@@ -10,7 +28,8 @@ error[E0019]: constant contains unimplemented expression type
 LL | /         while n != 0 {
 LL | |
 LL | |
-LL | |             n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
+LL | |
+...  |
 LL | |
 LL | |         }
    | |_________^
@@ -29,12 +48,12 @@ LL | |     }];
    | |_____^
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/infinite_loop.rs:10:20
+  --> $DIR/infinite_loop.rs:11: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 3 previous errors
+error: aborting due to 5 previous errors
 
-Some errors have detailed explanations: E0019, E0080.
+Some errors have detailed explanations: E0019, E0080, E0744.
 For more information about an error, try `rustc --explain E0019`.
diff --git a/src/test/ui/consts/const-eval/issue-52475.rs b/src/test/ui/consts/const-eval/issue-52475.rs
index b42249e57fa..b9cdf09b85f 100644
--- a/src/test/ui/consts/const-eval/issue-52475.rs
+++ b/src/test/ui/consts/const-eval/issue-52475.rs
@@ -4,7 +4,8 @@ fn main() {
         let mut x = &0;
         let mut n = 0;
         while n < 5 {
-        //~^ ERROR constant contains unimplemented expression type
+        //~^ ERROR `while` is not allowed in a `const`
+        //~| 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 1e83cbcff2b..25d56e3fac4 100644
--- a/src/test/ui/consts/const-eval/issue-52475.stderr
+++ b/src/test/ui/consts/const-eval/issue-52475.stderr
@@ -1,3 +1,15 @@
+error[E0744]: `while` is not allowed in a `const`
+  --> $DIR/issue-52475.rs:6:9
+   |
+LL | /         while n < 5 {
+LL | |
+LL | |
+LL | |
+LL | |             n = (n + 1) % 5;
+LL | |             x = &0; // Materialize a new AllocId
+LL | |         }
+   | |_________^
+
 error[E0019]: constant contains unimplemented expression type
   --> $DIR/issue-52475.rs:6:15
    |
@@ -10,6 +22,7 @@ error[E0019]: constant contains unimplemented expression type
 LL | /         while n < 5 {
 LL | |
 LL | |
+LL | |
 LL | |             n = (n + 1) % 5;
 LL | |             x = &0; // Materialize a new AllocId
 LL | |         }
@@ -29,12 +42,12 @@ LL | |     }];
    | |_____^
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/issue-52475.rs:9:17
+  --> $DIR/issue-52475.rs:10:17
    |
 LL |             n = (n + 1) % 5;
    |                 ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0019, E0080.
+Some errors have detailed explanations: E0019, E0080, E0744.
 For more information about an error, try `rustc --explain E0019`.
diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.rs b/src/test/ui/consts/const-eval/match-test-ptr-null.rs
index 5b89b0262ac..0dc3652bbee 100644
--- a/src/test/ui/consts/const-eval/match-test-ptr-null.rs
+++ b/src/test/ui/consts/const-eval/match-test-ptr-null.rs
@@ -5,6 +5,7 @@ fn main() {
     let _: [u8; 0] = [4; {
         match &1 as *const i32 as usize {
             //~^ ERROR casting pointers to integers in constants
+            //~| ERROR `match` is not allowed in a `const`
             //~| ERROR constant contains unimplemented expression type
             //~| ERROR evaluation of constant value failed
             0 => 42, //~ ERROR constant contains unimplemented expression type
diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr
index 3d34ac42662..ab4d28c0455 100644
--- a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr
+++ b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr
@@ -1,3 +1,15 @@
+error[E0744]: `match` is not allowed in a `const`
+  --> $DIR/match-test-ptr-null.rs:6:9
+   |
+LL | /         match &1 as *const i32 as usize {
+LL | |
+LL | |
+LL | |
+...  |
+LL | |             n => n,
+LL | |         }
+   | |_________^
+
 error[E0658]: casting pointers to integers in constants is unstable
   --> $DIR/match-test-ptr-null.rs:6:15
    |
@@ -14,7 +26,7 @@ LL |         match &1 as *const i32 as usize {
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0019]: constant contains unimplemented expression type
-  --> $DIR/match-test-ptr-null.rs:10:13
+  --> $DIR/match-test-ptr-null.rs:11:13
    |
 LL |             0 => 42,
    |             ^
@@ -25,7 +37,7 @@ error[E0080]: evaluation of constant value failed
 LL |         match &1 as *const i32 as usize {
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
 
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
 
-Some errors have detailed explanations: E0019, E0080, E0658.
+Some errors have detailed explanations: E0019, E0080, E0658, E0744.
 For more information about an error, try `rustc --explain E0019`.