diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 4f015ed1ce161..fbd5bc538e900 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -27,7 +27,7 @@ declare_lint! { declare_lint! { pub CONST_ERR, - Warn, + Deny, "constant evaluation detected erroneous expression" } diff --git a/src/test/compile-fail/array_const_index-0.rs b/src/test/compile-fail/array_const_index-0.rs index 9b9deb4ca8d9d..91007fcd63a28 100644 --- a/src/test/compile-fail/array_const_index-0.rs +++ b/src/test/compile-fail/array_const_index-0.rs @@ -10,9 +10,8 @@ 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 +//~^ index out of bounds: the len is 0 but the index is 1 +//~| ERROR 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 46feb20cf11dd..66739d308a70f 100644 --- a/src/test/compile-fail/array_const_index-1.rs +++ b/src/test/compile-fail/array_const_index-1.rs @@ -10,9 +10,8 @@ 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 +//~^ index out of bounds: the len is 0 but the index is 1 +//~| ERROR this constant cannot be used fn main() { let _ = B; diff --git a/src/test/compile-fail/const-slice-oob.rs b/src/test/compile-fail/const-slice-oob.rs index 7da5a2f17eaf9..6d51ff3099809 100644 --- a/src/test/compile-fail/const-slice-oob.rs +++ b/src/test/compile-fail/const-slice-oob.rs @@ -12,9 +12,8 @@ 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 +//~^ index out of bounds: the len is 3 but the index is 5 +//~| ERROR this constant cannot be used fn main() { let _ = BAR; diff --git a/src/test/compile-fail/eval-enum.rs b/src/test/compile-fail/eval-enum.rs index 49f76c532df54..7315616860293 100644 --- a/src/test/compile-fail/eval-enum.rs +++ b/src/test/compile-fail/eval-enum.rs @@ -12,11 +12,11 @@ enum Test { DivZero = 1/0, //~^ attempt to divide by zero //~| ERROR constant evaluation error - //~| WARN constant evaluation error + //~| ERROR constant evaluation error RemZero = 1%0, //~^ attempt to calculate the remainder with a divisor of zero //~| ERROR constant evaluation error - //~| WARN constant evaluation error + //~| ERROR constant evaluation error } fn main() {} diff --git a/src/test/incremental/warnings-reemitted.rs b/src/test/incremental/warnings-reemitted.rs index d50ffff5c1e14..1ea436d8ad192 100644 --- a/src/test/incremental/warnings-reemitted.rs +++ b/src/test/incremental/warnings-reemitted.rs @@ -13,6 +13,7 @@ // compile-pass #![allow(warnings)] +#![warn(const_err)] fn main() { 255u8 + 1; //~ WARNING this expression will panic at run-time diff --git a/src/test/run-fail/overflowing-add.rs b/src/test/run-fail/overflowing-add.rs index 250f0726dc9d6..584701410ef83 100644 --- a/src/test/run-fail/overflowing-add.rs +++ b/src/test/run-fail/overflowing-add.rs @@ -11,6 +11,8 @@ // error-pattern:thread 'main' panicked at 'attempt to add with overflow' // compile-flags: -C debug-assertions +#![allow(const_err)] + fn main() { let _x = 200u8 + 200u8 + 200u8; } diff --git a/src/test/run-fail/overflowing-mul.rs b/src/test/run-fail/overflowing-mul.rs index b47d0fc4136cc..5d6f59e02296b 100644 --- a/src/test/run-fail/overflowing-mul.rs +++ b/src/test/run-fail/overflowing-mul.rs @@ -11,6 +11,8 @@ // error-pattern:thread 'main' panicked at 'attempt to multiply with overflow' // compile-flags: -C debug-assertions +#![allow(const_err)] + fn main() { let x = 200u8 * 4; } diff --git a/src/test/run-fail/overflowing-neg.rs b/src/test/run-fail/overflowing-neg.rs index 836d7e37319e9..e7c518f1286fb 100644 --- a/src/test/run-fail/overflowing-neg.rs +++ b/src/test/run-fail/overflowing-neg.rs @@ -11,6 +11,8 @@ // error-pattern:thread 'main' panicked at 'attempt to negate with overflow' // compile-flags: -C debug-assertions +#![allow(const_err)] + fn main() { let _x = -std::i8::MIN; } diff --git a/src/test/run-fail/overflowing-sub.rs b/src/test/run-fail/overflowing-sub.rs index f94cb31b16884..404921a1af552 100644 --- a/src/test/run-fail/overflowing-sub.rs +++ b/src/test/run-fail/overflowing-sub.rs @@ -11,6 +11,8 @@ // error-pattern:thread 'main' panicked at 'attempt to subtract with overflow' // compile-flags: -C debug-assertions +#![allow(const_err)] + fn main() { let _x = 42u8 - (42u8 + 1); } diff --git a/src/test/ui/const-eval-overflow-2.rs b/src/test/ui/const-eval-overflow-2.rs index 885edb55ed86c..63f33cafaf827 100644 --- a/src/test/ui/const-eval-overflow-2.rs +++ b/src/test/ui/const-eval-overflow-2.rs @@ -11,7 +11,7 @@ // Evaluation of constants in refutable patterns goes through // different compiler control-flow paths. -#![allow(unused_imports, warnings)] +#![allow(unused_imports, warnings, const_err)] use std::fmt; use std::{i8, i16, i32, i64, isize}; diff --git a/src/test/ui/const-eval-overflow-4.rs b/src/test/ui/const-eval-overflow-4.rs index 24e178152eef0..ed14036b0b4cb 100644 --- a/src/test/ui/const-eval-overflow-4.rs +++ b/src/test/ui/const-eval-overflow-4.rs @@ -22,7 +22,7 @@ use std::{u8, u16, u32, u64, usize}; const A_I8_T : [u32; (i8::MAX as i8 + 1i8) as usize] //~^ ERROR E0080 - //~| WARN attempt to add with overflow + //~| ERROR attempt to add with overflow = [0; (i8::MAX as usize) + 1]; fn main() { diff --git a/src/test/ui/const-eval-overflow-4.stderr b/src/test/ui/const-eval-overflow-4.stderr index db0a6fc820446..fc4762f0554f7 100644 --- a/src/test/ui/const-eval-overflow-4.stderr +++ b/src/test/ui/const-eval-overflow-4.stderr @@ -1,10 +1,10 @@ -warning: attempt to add with overflow +error: attempt to add with overflow --> $DIR/const-eval-overflow-4.rs:23:13 | LL | : [u32; (i8::MAX as i8 + 1i8) as usize] | ^^^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(const_err)] on by default + = note: #[deny(const_err)] on by default error[E0080]: constant evaluation error --> $DIR/const-eval-overflow-4.rs:23:13 @@ -12,6 +12,6 @@ error[E0080]: constant evaluation error LL | : [u32; (i8::MAX as i8 + 1i8) as usize] | ^^^^^^^^^^^^^^^^^^^^^ attempt to add with overflow -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/const-eval/conditional_array_execution.rs b/src/test/ui/const-eval/conditional_array_execution.rs index dbddee862e022..8952a8386d7b8 100644 --- a/src/test/ui/const-eval/conditional_array_execution.rs +++ b/src/test/ui/const-eval/conditional_array_execution.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-pass +#![warn(const_err)] const X: u32 = 5; const Y: u32 = 6; diff --git a/src/test/ui/const-eval/conditional_array_execution.stderr b/src/test/ui/const-eval/conditional_array_execution.stderr index 713b1b36c08b1..5cf73b9fad66d 100644 --- a/src/test/ui/const-eval/conditional_array_execution.stderr +++ b/src/test/ui/const-eval/conditional_array_execution.stderr @@ -1,19 +1,23 @@ warning: attempt to subtract with overflow - --> $DIR/conditional_array_execution.rs:15:19 + --> $DIR/conditional_array_execution.rs:16:19 | LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; | ^^^^^ | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/conditional_array_execution.rs:12:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: this constant cannot be used - --> $DIR/conditional_array_execution.rs:15:1 + --> $DIR/conditional_array_execution.rs:16: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:20:20 + --> $DIR/conditional_array_execution.rs:21: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 097fba4d3c450..7ec100e411b36 100644 --- a/src/test/ui/const-eval/issue-43197.rs +++ b/src/test/ui/const-eval/issue-43197.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-pass +#![warn(const_err)] #![feature(const_fn)] diff --git a/src/test/ui/const-eval/issue-43197.stderr b/src/test/ui/const-eval/issue-43197.stderr index a22e8016296c4..d0e13d5657e75 100644 --- a/src/test/ui/const-eval/issue-43197.stderr +++ b/src/test/ui/const-eval/issue-43197.stderr @@ -1,37 +1,41 @@ warning: attempt to subtract with overflow - --> $DIR/issue-43197.rs:20:20 + --> $DIR/issue-43197.rs:21:20 | LL | const X: u32 = 0-1; | ^^^ | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/issue-43197.rs:12:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: this constant cannot be used - --> $DIR/issue-43197.rs:20:5 + --> $DIR/issue-43197.rs:21:5 | LL | const X: u32 = 0-1; | ^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow warning: attempt to subtract with overflow - --> $DIR/issue-43197.rs:23:24 + --> $DIR/issue-43197.rs:24:24 | LL | const Y: u32 = foo(0-1); | ^^^ warning: this constant cannot be used - --> $DIR/issue-43197.rs:23:5 + --> $DIR/issue-43197.rs:24:5 | LL | const Y: u32 = foo(0-1); | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow warning: constant evaluation error - --> $DIR/issue-43197.rs:26:23 + --> $DIR/issue-43197.rs:27:23 | LL | println!("{} {}", X, Y); | ^ referenced constant has errors warning: constant evaluation error - --> $DIR/issue-43197.rs:26:26 + --> $DIR/issue-43197.rs:27:26 | LL | println!("{} {}", X, Y); | ^ referenced constant has errors diff --git a/src/test/ui/const-eval/issue-44578.rs b/src/test/ui/const-eval/issue-44578.rs index 765113cfbb9e2..4133a8864f619 100644 --- a/src/test/ui/const-eval/issue-44578.rs +++ b/src/test/ui/const-eval/issue-44578.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-pass +#![warn(const_err)] trait Foo { const AMT: usize; diff --git a/src/test/ui/const-eval/issue-44578.stderr b/src/test/ui/const-eval/issue-44578.stderr index 01c6fa3623f8d..ce6ff86610aa5 100644 --- a/src/test/ui/const-eval/issue-44578.stderr +++ b/src/test/ui/const-eval/issue-44578.stderr @@ -1,13 +1,17 @@ warning: constant evaluation error - --> $DIR/issue-44578.rs:35:20 + --> $DIR/issue-44578.rs:36:20 | LL | println!("{}", as Foo>::AMT); //~ WARN const_err | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/issue-44578.rs:12:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: constant evaluation error - --> $DIR/issue-44578.rs:35:20 + --> $DIR/issue-44578.rs:36:20 | LL | println!("{}", as Foo>::AMT); //~ WARN const_err | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors diff --git a/src/test/ui/const-eval/promoted_errors.rs b/src/test/ui/const-eval/promoted_errors.rs index dc30c7f9cce04..7385860abae28 100644 --- a/src/test/ui/const-eval/promoted_errors.rs +++ b/src/test/ui/const-eval/promoted_errors.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![warn(const_err)] + // compile-pass // compile-flags: -O fn main() { diff --git a/src/test/ui/const-eval/promoted_errors.stderr b/src/test/ui/const-eval/promoted_errors.stderr index 7761f192fdb70..8e9a0ea43a43b 100644 --- a/src/test/ui/const-eval/promoted_errors.stderr +++ b/src/test/ui/const-eval/promoted_errors.stderr @@ -1,49 +1,53 @@ warning: constant evaluation error - --> $DIR/promoted_errors.rs:14:20 + --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 0u32 - 1); | ^^^^^^^^ attempt to subtract with overflow | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/promoted_errors.rs:11:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: constant evaluation error - --> $DIR/promoted_errors.rs:14:20 + --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 0u32 - 1); | ^^^^^^^^ attempt to subtract with overflow warning: constant evaluation error - --> $DIR/promoted_errors.rs:17:14 + --> $DIR/promoted_errors.rs:19:14 | LL | let _x = 0u32 - 1; | ^^^^^^^^ attempt to subtract with overflow warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:19:20 + --> $DIR/promoted_errors.rs:21:20 | LL | println!("{}", 1/(1-1)); | ^^^^^^^ warning: constant evaluation error - --> $DIR/promoted_errors.rs:19:20 + --> $DIR/promoted_errors.rs:21:20 | LL | println!("{}", 1/(1-1)); | ^^^^^^^ attempt to divide by zero warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:22:14 + --> $DIR/promoted_errors.rs:24:14 | LL | let _x = 1/(1-1); | ^^^^^^^ warning: constant evaluation error - --> $DIR/promoted_errors.rs:22:14 + --> $DIR/promoted_errors.rs:24:14 | LL | let _x = 1/(1-1); | ^^^^^^^ attempt to divide by zero warning: constant evaluation error - --> $DIR/promoted_errors.rs:25:20 + --> $DIR/promoted_errors.rs:27:20 | LL | println!("{}", 1/(false as u32)); | ^^^^^^^^^^^^^^^^ attempt to divide by zero diff --git a/src/test/ui/const-eval/pub_const_err.rs b/src/test/ui/const-eval/pub_const_err.rs index c6bf07649af38..ef8fdb33d748a 100644 --- a/src/test/ui/const-eval/pub_const_err.rs +++ b/src/test/ui/const-eval/pub_const_err.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-pass +#![warn(const_err)] #![crate_type = "lib"] diff --git a/src/test/ui/const-eval/pub_const_err.stderr b/src/test/ui/const-eval/pub_const_err.stderr index 2981ac20cd981..068825f1cd310 100644 --- a/src/test/ui/const-eval/pub_const_err.stderr +++ b/src/test/ui/const-eval/pub_const_err.stderr @@ -1,25 +1,29 @@ warning: attempt to subtract with overflow - --> $DIR/pub_const_err.rs:15:20 + --> $DIR/pub_const_err.rs:16:20 | LL | pub const Z: u32 = 0 - 1; | ^^^^^ | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/pub_const_err.rs:12:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: this constant cannot be used - --> $DIR/pub_const_err.rs:15:1 + --> $DIR/pub_const_err.rs:16:1 | LL | pub const Z: u32 = 0 - 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow warning: attempt to subtract with overflow - --> $DIR/pub_const_err.rs:19:22 + --> $DIR/pub_const_err.rs:20:22 | LL | pub type Foo = [i32; 0 - 1]; | ^^^^^ warning: this array length cannot be used - --> $DIR/pub_const_err.rs:19:22 + --> $DIR/pub_const_err.rs:20: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 index d87cb7ed77079..f65da1d8674a2 100644 --- a/src/test/ui/const-eval/pub_const_err_bin.rs +++ b/src/test/ui/const-eval/pub_const_err_bin.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-pass +#![warn(const_err)] pub const Z: u32 = 0 - 1; //~^ WARN attempt to subtract with overflow diff --git a/src/test/ui/const-eval/pub_const_err_bin.stderr b/src/test/ui/const-eval/pub_const_err_bin.stderr index 3e8966d854bf0..dcb8125fc55bc 100644 --- a/src/test/ui/const-eval/pub_const_err_bin.stderr +++ b/src/test/ui/const-eval/pub_const_err_bin.stderr @@ -1,25 +1,29 @@ warning: attempt to subtract with overflow - --> $DIR/pub_const_err_bin.rs:13:20 + --> $DIR/pub_const_err_bin.rs:14:20 | LL | pub const Z: u32 = 0 - 1; | ^^^^^ | - = note: #[warn(const_err)] on by default +note: lint level defined here + --> $DIR/pub_const_err_bin.rs:12:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ warning: this constant cannot be used - --> $DIR/pub_const_err_bin.rs:13:1 + --> $DIR/pub_const_err_bin.rs:14: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 + --> $DIR/pub_const_err_bin.rs:18:22 | LL | pub type Foo = [i32; 0 - 1]; | ^^^^^ warning: this array length cannot be used - --> $DIR/pub_const_err_bin.rs:17:22 + --> $DIR/pub_const_err_bin.rs:18:22 | LL | pub type Foo = [i32; 0 - 1]; | ^^^^^ attempt to subtract with overflow diff --git a/src/test/ui/const-len-underflow-separate-spans.rs b/src/test/ui/const-len-underflow-separate-spans.rs index ee07dabab1fc8..453e332a903c7 100644 --- a/src/test/ui/const-len-underflow-separate-spans.rs +++ b/src/test/ui/const-len-underflow-separate-spans.rs @@ -16,7 +16,7 @@ const ONE: usize = 1; const TWO: usize = 2; const LEN: usize = ONE - TWO; //~^ ERROR E0080 -//~| WARN attempt to subtract with overflow +//~| ERROR attempt to subtract with overflow fn main() { let a: [i8; LEN] = unimplemented!(); diff --git a/src/test/ui/const-len-underflow-separate-spans.stderr b/src/test/ui/const-len-underflow-separate-spans.stderr index 8d737dbfc0857..48ff7a81c24ee 100644 --- a/src/test/ui/const-len-underflow-separate-spans.stderr +++ b/src/test/ui/const-len-underflow-separate-spans.stderr @@ -1,10 +1,10 @@ -warning: attempt to subtract with overflow +error: attempt to subtract with overflow --> $DIR/const-len-underflow-separate-spans.rs:17:20 | LL | const LEN: usize = ONE - TWO; | ^^^^^^^^^ | - = note: #[warn(const_err)] on by default + = note: #[deny(const_err)] on by default error[E0080]: constant evaluation error --> $DIR/const-len-underflow-separate-spans.rs:17:20 @@ -18,6 +18,6 @@ error[E0080]: constant evaluation error LL | let a: [i8; LEN] = unimplemented!(); | ^^^ referenced constant has errors -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/error-codes/E0080.stderr b/src/test/ui/error-codes/E0080.stderr index 5e401bd6c79da..25ec5c458312d 100644 --- a/src/test/ui/error-codes/E0080.stderr +++ b/src/test/ui/error-codes/E0080.stderr @@ -12,15 +12,15 @@ error[E0080]: constant evaluation error LL | X = (1 << 500), //~ ERROR E0080 | ^^^^^^^^^^ attempt to shift left with overflow -warning: attempt to divide by zero +error: attempt to divide by zero --> $DIR/E0080.rs:14:9 | LL | Y = (1 / 0) //~ ERROR E0080 | ^^^^^^^ | - = note: #[warn(const_err)] on by default + = note: #[deny(const_err)] on by default -warning: constant evaluation error +error: constant evaluation error --> $DIR/E0080.rs:14:9 | LL | Y = (1 / 0) //~ ERROR E0080 @@ -32,6 +32,6 @@ error[E0080]: constant evaluation error LL | Y = (1 / 0) //~ ERROR E0080 | ^^^^^^^ attempt to divide by zero -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0080`.