Skip to content

Commit

Permalink
Auto merge of rust-lang#102091 - RalfJung:const_err, r=oli-obk
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 7, 2022
2 parents 9125d0d + 1375e53 commit 71d72ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
1 change: 0 additions & 1 deletion tests/fail/erroneous_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Inlining changes the error location
//@compile-flags: -Zmir-opt-level=0
#![feature(never_type)]
#![warn(warnings, const_err)]

struct PrintName<T>(T);
impl<T> PrintName<T> {
Expand Down
8 changes: 2 additions & 6 deletions tests/fail/erroneous_const2.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const X: u32 = 5;
const Y: u32 = 6;
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
//~^ERROR: any use of this value
//~|WARN: previously accepted
//~^ERROR: evaluation of constant value failed

#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
fn main() {
println!("{}", FOO); //~ERROR: post-monomorphization error
//~|ERROR: evaluation of constant value failed
//~|ERROR: erroneous constant used
//~|WARN: previously accepted
println!("{}", FOO);
}
36 changes: 3 additions & 33 deletions tests/fail/erroneous_const2.stderr
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
error: any use of this value will cause an error
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
| -------------- ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: `#[deny(const_err)]` on by default

error[E0080]: evaluation of constant value failed
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^ referenced constant has errors

error: erroneous constant used
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^ referenced constant has errors
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= 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)

error: post-monomorphization error: referenced constant has errors
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^ referenced constant has errors
|
= note: inside `main` at $DIR/erroneous_const2.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
| ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow

error: aborting due to 4 previous errors
error: aborting due to previous error

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

0 comments on commit 71d72ff

Please sign in to comment.