about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2018-04-20 14:18:29 +0200
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2018-04-24 13:11:48 +0200
commitcd6c186e4eb410413522e2be2ef6309edf3d0b32 (patch)
treefe3f5e008cd252804e323c692124386384bf5197 /src/test
parent52ed3d8761dc42e51429eb3bbf56a94d14fdd5c6 (diff)
Warn on all erroneous constants
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/array_const_index-0.rs1
-rw-r--r--src/test/compile-fail/array_const_index-1.rs1
-rw-r--r--src/test/compile-fail/const-err-early.rs18
-rw-r--r--src/test/compile-fail/const-err-multi.rs7
-rw-r--r--src/test/compile-fail/const-eval-overflow2.rs32
-rw-r--r--src/test/compile-fail/const-eval-overflow2b.rs32
-rw-r--r--src/test/compile-fail/const-eval-overflow2c.rs32
-rw-r--r--src/test/compile-fail/const-slice-oob.rs1
-rw-r--r--src/test/ui/const-eval/conditional_array_execution.rs1
-rw-r--r--src/test/ui/const-eval/conditional_array_execution.stderr8
-rw-r--r--src/test/ui/const-eval/issue-43197.rs2
-rw-r--r--src/test/ui/const-eval/issue-43197.stderr24
-rw-r--r--src/test/ui/const-eval/pub_const_err.rs9
-rw-r--r--src/test/ui/const-eval/pub_const_err.stderr24
-rw-r--r--src/test/ui/const-eval/pub_const_err_bin.rs21
-rw-r--r--src/test/ui/const-eval/pub_const_err_bin.stderr26
16 files changed, 164 insertions, 75 deletions
diff --git a/src/test/compile-fail/array_const_index-0.rs b/src/test/compile-fail/array_const_index-0.rs
index 501c66e75cd..9b9deb4ca8d 100644
--- a/src/test/compile-fail/array_const_index-0.rs
+++ b/src/test/compile-fail/array_const_index-0.rs
@@ -12,6 +12,7 @@ const A: &'static [i32] = &[];
 const B: i32 = (&A)[1];
 //~^ ERROR constant evaluation error
 //~| index out of bounds: the len is 0 but the index is 1
+//~| WARN this constant cannot be used
 
 fn main() {
     let _ = B;
diff --git a/src/test/compile-fail/array_const_index-1.rs b/src/test/compile-fail/array_const_index-1.rs
index d3b43e83bfe..46feb20cf11 100644
--- a/src/test/compile-fail/array_const_index-1.rs
+++ b/src/test/compile-fail/array_const_index-1.rs
@@ -12,6 +12,7 @@ const A: [i32; 0] = [];
 const B: i32 = A[1];
 //~^ ERROR constant evaluation error
 //~| index out of bounds: the len is 0 but the index is 1
+//~| WARN this constant cannot be used
 
 fn main() {
     let _ = B;
diff --git a/src/test/compile-fail/const-err-early.rs b/src/test/compile-fail/const-err-early.rs
index 3de0f1ff61e..6caec159d01 100644
--- a/src/test/compile-fail/const-err-early.rs
+++ b/src/test/compile-fail/const-err-early.rs
@@ -10,17 +10,17 @@
 
 #![deny(const_err)]
 
-pub const A: i8 = -std::i8::MIN; //~ ERROR E0080
-//~^ ERROR attempt to negate with overflow
+pub const A: i8 = -std::i8::MIN; //~ ERROR const_err
+//~^ ERROR this constant cannot be used
 //~| ERROR constant evaluation error
-pub const B: u8 = 200u8 + 200u8; //~ ERROR E0080
-//~^ ERROR attempt to add with overflow
-pub const C: u8 = 200u8 * 4; //~ ERROR E0080
-//~^ ERROR attempt to multiply with overflow
-pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR E0080
-//~^ ERROR attempt to subtract with overflow
+pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err
+//~^ ERROR this constant cannot be used
+pub const C: u8 = 200u8 * 4; //~ ERROR const_err
+//~^ ERROR this constant cannot be used
+pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err
+//~^ ERROR this constant cannot be used
 pub const E: u8 = [5u8][1];
-//~^ ERROR E0080
+//~^ ERROR const_err
 
 fn main() {
     let _a = A;
diff --git a/src/test/compile-fail/const-err-multi.rs b/src/test/compile-fail/const-err-multi.rs
index d2355f57f17..6f0281b8bd0 100644
--- a/src/test/compile-fail/const-err-multi.rs
+++ b/src/test/compile-fail/const-err-multi.rs
@@ -14,12 +14,13 @@ pub const A: i8 = -std::i8::MIN;
 //~^ ERROR E0080
 //~| ERROR attempt to negate with overflow
 //~| ERROR constant evaluation error
+//~| ERROR this constant cannot be used
 pub const B: i8 = A;
-//~^ ERROR E0080
+//~^ ERROR const_err
 pub const C: u8 = A as u8;
-//~^ ERROR E0080
+//~^ ERROR const_err
 pub const D: i8 = 50 - A;
-//~^ ERROR E0080
+//~^ ERROR const_err
 
 fn main() {
     let _ = (A, B, C, D);
diff --git a/src/test/compile-fail/const-eval-overflow2.rs b/src/test/compile-fail/const-eval-overflow2.rs
index a0d8f9672c0..faa8c3039b7 100644
--- a/src/test/compile-fail/const-eval-overflow2.rs
+++ b/src/test/compile-fail/const-eval-overflow2.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
+     //~^ ERROR this constant cannot be used
     (
      i8::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_I16: (i16,) =
+     //~^ ERROR this constant cannot be used
     (
      i16::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_I32: (i32,) =
+     //~^ ERROR this constant cannot be used
     (
      i32::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_I64: (i64,) =
+     //~^ ERROR this constant cannot be used
     (
      i64::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_U8: (u8,) =
+     //~^ ERROR this constant cannot be used
     (
      u8::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_U16: (u16,) = (
+     //~^ ERROR this constant cannot be used
      u16::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_U32: (u32,) = (
+     //~^ ERROR this constant cannot be used
      u32::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 const VALS_U64: (u64,) =
+     //~^ ERROR this constant cannot be used
     (
      u64::MIN - 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to subtract with overflow
+     //~^ ERROR attempt to subtract with overflow
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-eval-overflow2b.rs b/src/test/compile-fail/const-eval-overflow2b.rs
index 08128f90e53..d827e680c5b 100644
--- a/src/test/compile-fail/const-eval-overflow2b.rs
+++ b/src/test/compile-fail/const-eval-overflow2b.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
+     //~^ ERROR this constant cannot be used
     (
      i8::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_I16: (i16,) =
+     //~^ ERROR this constant cannot be used
     (
      i16::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_I32: (i32,) =
+     //~^ ERROR this constant cannot be used
     (
      i32::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_I64: (i64,) =
+     //~^ ERROR this constant cannot be used
     (
      i64::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_U8: (u8,) =
+     //~^ ERROR this constant cannot be used
     (
      u8::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_U16: (u16,) = (
+     //~^ ERROR this constant cannot be used
      u16::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_U32: (u32,) = (
+     //~^ ERROR this constant cannot be used
      u32::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 const VALS_U64: (u64,) =
+     //~^ ERROR this constant cannot be used
     (
      u64::MAX + 1,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to add with overflow
+     //~^ ERROR attempt to add with overflow
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-eval-overflow2c.rs b/src/test/compile-fail/const-eval-overflow2c.rs
index 31a1638cade..2fd46b038ef 100644
--- a/src/test/compile-fail/const-eval-overflow2c.rs
+++ b/src/test/compile-fail/const-eval-overflow2c.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
+     //~^ ERROR this constant cannot be used
     (
      i8::MIN * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_I16: (i16,) =
+     //~^ ERROR this constant cannot be used
     (
      i16::MIN * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_I32: (i32,) =
+     //~^ ERROR this constant cannot be used
     (
      i32::MIN * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_I64: (i64,) =
+     //~^ ERROR this constant cannot be used
     (
      i64::MIN * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_U8: (u8,) =
+     //~^ ERROR this constant cannot be used
     (
      u8::MAX * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_U16: (u16,) = (
+     //~^ ERROR this constant cannot be used
      u16::MAX * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_U32: (u32,) = (
+     //~^ ERROR this constant cannot be used
      u32::MAX * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 const VALS_U64: (u64,) =
+     //~^ ERROR this constant cannot be used
     (
      u64::MAX * 2,
-     //~^ ERROR constant evaluation error
-     //~| ERROR attempt to multiply with overflow
+     //~^ ERROR attempt to multiply with overflow
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-slice-oob.rs b/src/test/compile-fail/const-slice-oob.rs
index 179ea9e853f..7da5a2f17ea 100644
--- a/src/test/compile-fail/const-slice-oob.rs
+++ b/src/test/compile-fail/const-slice-oob.rs
@@ -14,6 +14,7 @@ const FOO: &'static[u32] = &[1, 2, 3];
 const BAR: u32 = FOO[5];
 //~^ ERROR constant evaluation error [E0080]
 //~| index out of bounds: the len is 3 but the index is 5
+//~| WARN this constant cannot be used
 
 fn main() {
     let _ = BAR;
diff --git a/src/test/ui/const-eval/conditional_array_execution.rs b/src/test/ui/const-eval/conditional_array_execution.rs
index e059c354d65..dbddee862e0 100644
--- a/src/test/ui/const-eval/conditional_array_execution.rs
+++ b/src/test/ui/const-eval/conditional_array_execution.rs
@@ -14,6 +14,7 @@ const X: u32 = 5;
 const Y: u32 = 6;
 const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
 //~^ WARN attempt to subtract with overflow
+//~| WARN this constant cannot be used
 
 fn main() {
     println!("{}", FOO);
diff --git a/src/test/ui/const-eval/conditional_array_execution.stderr b/src/test/ui/const-eval/conditional_array_execution.stderr
index fd29990fec2..713b1b36c08 100644
--- a/src/test/ui/const-eval/conditional_array_execution.stderr
+++ b/src/test/ui/const-eval/conditional_array_execution.stderr
@@ -6,8 +6,14 @@ LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
    |
    = note: #[warn(const_err)] on by default
 
+warning: this constant cannot be used
+  --> $DIR/conditional_array_execution.rs:15:1
+   |
+LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
+
 warning: constant evaluation error
-  --> $DIR/conditional_array_execution.rs:19:20
+  --> $DIR/conditional_array_execution.rs:20:20
    |
 LL |     println!("{}", FOO);
    |                    ^^^ referenced constant has errors
diff --git a/src/test/ui/const-eval/issue-43197.rs b/src/test/ui/const-eval/issue-43197.rs
index b27791ef533..097fba4d3c4 100644
--- a/src/test/ui/const-eval/issue-43197.rs
+++ b/src/test/ui/const-eval/issue-43197.rs
@@ -19,8 +19,10 @@ const fn foo(x: u32) -> u32 {
 fn main() {
     const X: u32 = 0-1;
     //~^ WARN attempt to subtract with overflow
+    //~| WARN this constant cannot be used
     const Y: u32 = foo(0-1);
     //~^ WARN attempt to subtract with overflow
+    //~| WARN this constant cannot be used
     println!("{} {}", X, Y);
     //~^ WARN constant evaluation error
     //~| WARN constant evaluation error
diff --git a/src/test/ui/const-eval/issue-43197.stderr b/src/test/ui/const-eval/issue-43197.stderr
index 5da47a85eb8..a22e8016296 100644
--- a/src/test/ui/const-eval/issue-43197.stderr
+++ b/src/test/ui/const-eval/issue-43197.stderr
@@ -6,20 +6,32 @@ LL |     const X: u32 = 0-1;
    |
    = note: #[warn(const_err)] on by default
 
-warning: constant evaluation error
-  --> $DIR/issue-43197.rs:24:23
+warning: this constant cannot be used
+  --> $DIR/issue-43197.rs:20:5
    |
-LL |     println!("{} {}", X, Y);
-   |                       ^ referenced constant has errors
+LL |     const X: u32 = 0-1;
+   |     ^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
 
 warning: attempt to subtract with overflow
-  --> $DIR/issue-43197.rs:22:24
+  --> $DIR/issue-43197.rs:23:24
    |
 LL |     const Y: u32 = foo(0-1);
    |                        ^^^
 
+warning: this constant cannot be used
+  --> $DIR/issue-43197.rs:23:5
+   |
+LL |     const Y: u32 = foo(0-1);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
+
+warning: constant evaluation error
+  --> $DIR/issue-43197.rs:26:23
+   |
+LL |     println!("{} {}", X, Y);
+   |                       ^ referenced constant has errors
+
 warning: constant evaluation error
-  --> $DIR/issue-43197.rs:24:26
+  --> $DIR/issue-43197.rs:26:26
    |
 LL |     println!("{} {}", X, Y);
    |                          ^ referenced constant has errors
diff --git a/src/test/ui/const-eval/pub_const_err.rs b/src/test/ui/const-eval/pub_const_err.rs
index bdb9f5b19a8..c6bf07649af 100644
--- a/src/test/ui/const-eval/pub_const_err.rs
+++ b/src/test/ui/const-eval/pub_const_err.rs
@@ -8,9 +8,14 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![deny(const_err)]
+// compile-pass
 
 #![crate_type = "lib"]
 
 pub const Z: u32 = 0 - 1;
-//~^ ERROR attempt to subtract with overflow
+//~^ WARN attempt to subtract with overflow
+//~| WARN this constant cannot be used
+
+pub type Foo = [i32; 0 - 1];
+//~^ WARN attempt to subtract with overflow
+//~| WARN this array length cannot be used
diff --git a/src/test/ui/const-eval/pub_const_err.stderr b/src/test/ui/const-eval/pub_const_err.stderr
index b77ec38ca16..2981ac20cd9 100644
--- a/src/test/ui/const-eval/pub_const_err.stderr
+++ b/src/test/ui/const-eval/pub_const_err.stderr
@@ -1,14 +1,26 @@
-error: attempt to subtract with overflow
+warning: attempt to subtract with overflow
   --> $DIR/pub_const_err.rs:15:20
    |
 LL | pub const Z: u32 = 0 - 1;
    |                    ^^^^^
    |
-note: lint level defined here
-  --> $DIR/pub_const_err.rs:11:9
+   = note: #[warn(const_err)] on by default
+
+warning: this constant cannot be used
+  --> $DIR/pub_const_err.rs:15:1
    |
-LL | #![deny(const_err)]
-   |         ^^^^^^^^^
+LL | pub const Z: u32 = 0 - 1;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
 
-error: aborting due to previous error
+warning: attempt to subtract with overflow
+  --> $DIR/pub_const_err.rs:19:22
+   |
+LL | pub type Foo = [i32; 0 - 1];
+   |                      ^^^^^
+
+warning: this array length cannot be used
+  --> $DIR/pub_const_err.rs:19:22
+   |
+LL | pub type Foo = [i32; 0 - 1];
+   |                      ^^^^^ attempt to subtract with overflow
 
diff --git a/src/test/ui/const-eval/pub_const_err_bin.rs b/src/test/ui/const-eval/pub_const_err_bin.rs
new file mode 100644
index 00000000000..d87cb7ed770
--- /dev/null
+++ b/src/test/ui/const-eval/pub_const_err_bin.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-pass
+
+pub const Z: u32 = 0 - 1;
+//~^ WARN attempt to subtract with overflow
+//~| WARN this constant cannot be used
+
+pub type Foo = [i32; 0 - 1];
+//~^ WARN attempt to subtract with overflow
+//~| WARN this array length cannot be used
+
+fn main() {}
diff --git a/src/test/ui/const-eval/pub_const_err_bin.stderr b/src/test/ui/const-eval/pub_const_err_bin.stderr
new file mode 100644
index 00000000000..3e8966d854b
--- /dev/null
+++ b/src/test/ui/const-eval/pub_const_err_bin.stderr
@@ -0,0 +1,26 @@
+warning: attempt to subtract with overflow
+  --> $DIR/pub_const_err_bin.rs:13:20
+   |
+LL | pub const Z: u32 = 0 - 1;
+   |                    ^^^^^
+   |
+   = note: #[warn(const_err)] on by default
+
+warning: this constant cannot be used
+  --> $DIR/pub_const_err_bin.rs:13:1
+   |
+LL | pub const Z: u32 = 0 - 1;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
+
+warning: attempt to subtract with overflow
+  --> $DIR/pub_const_err_bin.rs:17:22
+   |
+LL | pub type Foo = [i32; 0 - 1];
+   |                      ^^^^^
+
+warning: this array length cannot be used
+  --> $DIR/pub_const_err_bin.rs:17:22
+   |
+LL | pub type Foo = [i32; 0 - 1];
+   |                      ^^^^^ attempt to subtract with overflow
+