Skip to content

Commit 71d72ff

Browse files
committed
Auto merge of rust-lang#102091 - RalfJung:const_err, r=oli-obk
make const_err a hard error This lint has been deny-by-default with future incompat wording since [Rust 1.51](rust-lang#80394) and the stable release of this week starts showing it in cargo's future compat reports. I can't wait to finally get rid of at least some of the mess in our const-err-reporting-code. ;) r? `@oli-obk` Fixes rust-lang#71800 Fixes rust-lang#100114
2 parents 9125d0d + 1375e53 commit 71d72ff

File tree

3 files changed

+5
-40
lines changed

3 files changed

+5
-40
lines changed

tests/fail/erroneous_const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Inlining changes the error location
44
//@compile-flags: -Zmir-opt-level=0
55
#![feature(never_type)]
6-
#![warn(warnings, const_err)]
76

87
struct PrintName<T>(T);
98
impl<T> PrintName<T> {

tests/fail/erroneous_const2.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
const X: u32 = 5;
22
const Y: u32 = 6;
33
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
4-
//~^ERROR: any use of this value
5-
//~|WARN: previously accepted
4+
//~^ERROR: evaluation of constant value failed
65

76
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
87
fn main() {
9-
println!("{}", FOO); //~ERROR: post-monomorphization error
10-
//~|ERROR: evaluation of constant value failed
11-
//~|ERROR: erroneous constant used
12-
//~|WARN: previously accepted
8+
println!("{}", FOO);
139
}

tests/fail/erroneous_const2.stderr

+3-33
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
1-
error: any use of this value will cause an error
2-
--> $DIR/erroneous_const2.rs:LL:CC
3-
|
4-
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
5-
| -------------- ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
9-
= note: `#[deny(const_err)]` on by default
10-
111
error[E0080]: evaluation of constant value failed
122
--> $DIR/erroneous_const2.rs:LL:CC
133
|
14-
LL | println!("{}", FOO);
15-
| ^^^ referenced constant has errors
16-
17-
error: erroneous constant used
18-
--> $DIR/erroneous_const2.rs:LL:CC
19-
|
20-
LL | println!("{}", FOO);
21-
| ^^^ referenced constant has errors
22-
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
25-
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
26-
27-
error: post-monomorphization error: referenced constant has errors
28-
--> $DIR/erroneous_const2.rs:LL:CC
29-
|
30-
LL | println!("{}", FOO);
31-
| ^^^ referenced constant has errors
32-
|
33-
= note: inside `main` at $DIR/erroneous_const2.rs:LL:CC
34-
35-
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
4+
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
5+
| ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
366

37-
error: aborting due to 4 previous errors
7+
error: aborting due to previous error
388

399
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)