Skip to content

Commit 8477d35

Browse files
committed
make const_err a future incompat lint
1 parent d6a28a9 commit 8477d35

File tree

107 files changed

+952
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+952
-261
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ declare_lint! {
255255
pub CONST_ERR,
256256
Deny,
257257
"constant evaluation encountered erroneous expression",
258+
@future_incompatible = FutureIncompatibleInfo {
259+
reference: "issue #71800 <https://github.com/rust-lang/rust/issues/71800>",
260+
edition: None,
261+
};
258262
report_in_external_macro
259263
}
260264

src/test/ui/array-slice-vec/array_const_index-0.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const A: &'static [i32] = &[];
22
const B: i32 = (&A)[1];
33
//~^ index out of bounds: the length is 0 but the index is 1
44
//~| ERROR any use of this value will cause an error
5+
//~| WARN this was previously accepted by the compiler but is being phased out
56

67
fn main() {
78
let _ = B;

src/test/ui/array-slice-vec/array_const_index-0.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ LL | const B: i32 = (&A)[1];
77
| index out of bounds: the length is 0 but the index is 1
88
|
99
= note: `#[deny(const_err)]` on by default
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1012

1113
error: aborting due to previous error
1214

src/test/ui/array-slice-vec/array_const_index-1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const A: [i32; 0] = [];
22
const B: i32 = A[1];
33
//~^ index out of bounds: the length is 0 but the index is 1
44
//~| ERROR any use of this value will cause an error
5+
//~| WARN this was previously accepted by the compiler but is being phased out
56

67
fn main() {
78
let _ = B;

src/test/ui/array-slice-vec/array_const_index-1.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ LL | const B: i32 = A[1];
77
| index out of bounds: the length is 0 but the index is 1
88
|
99
= note: `#[deny(const_err)]` on by default
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1012

1113
error: aborting due to previous error
1214

src/test/ui/associated-consts/defaults-not-assumed-fail.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ trait Tr {
77
// `Self::A` must not be assumed to hold inside the trait.
88
const B: u8 = Self::A + 1;
99
//~^ ERROR any use of this value will cause an error
10+
//~| WARN this was previously accepted by the compiler but is being phased out
1011
}
1112

1213
// An impl that doesn't override any constant will NOT cause a const eval error
@@ -33,6 +34,7 @@ fn main() {
3334
assert_eq!(<() as Tr>::B, 0); // causes the error above
3435
//~^ ERROR evaluation of constant value failed
3536
//~| ERROR erroneous constant used
37+
//~| WARN this was previously accepted by the compiler but is being phased out
3638

3739
assert_eq!(<u8 as Tr>::A, 254);
3840
assert_eq!(<u8 as Tr>::B, 255);

src/test/ui/associated-consts/defaults-not-assumed-fail.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ LL | const B: u8 = Self::A + 1;
77
| attempt to compute `u8::MAX + 1_u8`, which would overflow
88
|
99
= note: `#[deny(const_err)]` on by default
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1012

1113
error[E0080]: evaluation of constant value failed
12-
--> $DIR/defaults-not-assumed-fail.rs:33:16
14+
--> $DIR/defaults-not-assumed-fail.rs:34:16
1315
|
1416
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
1517
| ^^^^^^^^^^^^^ referenced constant has errors
1618

1719
error: erroneous constant used
18-
--> $DIR/defaults-not-assumed-fail.rs:33:5
20+
--> $DIR/defaults-not-assumed-fail.rs:34:5
1921
|
2022
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
2123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
2224
|
25+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2327
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2428

2529
error: aborting due to 3 previous errors

src/test/ui/const-ptr/out_of_bounds_read.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
1515
| ------------------------------------------------------
1616
|
1717
= note: `#[deny(const_err)]` on by default
18+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1820

1921
error: any use of this value will cause an error
2022
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
@@ -32,6 +34,9 @@ LL | unsafe { copy_nonoverlapping(src, dst, count) }
3234
|
3335
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
3436
| --------------------------------------------------------
37+
|
38+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
39+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3540

3641
error: any use of this value will cause an error
3742
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
@@ -49,6 +54,9 @@ LL | unsafe { copy_nonoverlapping(src, dst, count) }
4954
|
5055
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
5156
| --------------------------------------------------------------------
57+
|
58+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
59+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
5260

5361
error: aborting due to 3 previous errors
5462

src/test/ui/consts/assoc_const_generic_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ trait ZeroSized: Sized {
99

1010
impl<T: Sized> ZeroSized for T {
1111
const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; //~ WARN any use of this value
12+
//~| WARN this was previously accepted by the compiler but is being phased out
1213
fn requires_zero_size(self) {
1314
let () = Self::I_AM_ZERO_SIZED; //~ ERROR erroneous constant encountered
1415
println!("requires_zero_size called");

src/test/ui/consts/assoc_const_generic_impl.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ note: the lint level is defined here
1111
|
1212
LL | #![warn(const_err)]
1313
| ^^^^^^^^^
14+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1416

1517
error: erroneous constant encountered
16-
--> $DIR/assoc_const_generic_impl.rs:13:18
18+
--> $DIR/assoc_const_generic_impl.rs:14:18
1719
|
1820
LL | let () = Self::I_AM_ZERO_SIZED;
1921
| ^^^^^^^^^^^^^^^^^^^^^

src/test/ui/consts/assume-type-intrinsics.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ LL | | };
1616
| |______-
1717
|
1818
= note: `#[deny(const_err)]` on by default
19+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
20+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1921

2022
error: aborting due to previous error
2123

src/test/ui/consts/const-err-early.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#![deny(const_err)]
22

33
pub const A: i8 = -i8::MIN; //~ ERROR const_err
4+
//~| WARN this was previously accepted by the compiler but is being phased out
45
pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err
6+
//~| WARN this was previously accepted by the compiler but is being phased out
57
pub const C: u8 = 200u8 * 4; //~ ERROR const_err
8+
//~| WARN this was previously accepted by the compiler but is being phased out
69
pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err
10+
//~| WARN this was previously accepted by the compiler but is being phased out
711
pub const E: u8 = [5u8][1]; //~ ERROR const_err
12+
//~| WARN this was previously accepted by the compiler but is being phased out
813

914
fn main() {
1015
let _a = A;

src/test/ui/consts/const-err-early.stderr

+18-4
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,52 @@ note: the lint level is defined here
1111
|
1212
LL | #![deny(const_err)]
1313
| ^^^^^^^^^
14+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1416

1517
error: any use of this value will cause an error
16-
--> $DIR/const-err-early.rs:4:19
18+
--> $DIR/const-err-early.rs:5:19
1719
|
1820
LL | pub const B: u8 = 200u8 + 200u8;
1921
| ------------------^^^^^^^^^^^^^-
2022
| |
2123
| attempt to compute `200_u8 + 200_u8`, which would overflow
24+
|
25+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2227

2328
error: any use of this value will cause an error
24-
--> $DIR/const-err-early.rs:5:19
29+
--> $DIR/const-err-early.rs:7:19
2530
|
2631
LL | pub const C: u8 = 200u8 * 4;
2732
| ------------------^^^^^^^^^-
2833
| |
2934
| attempt to compute `200_u8 * 4_u8`, which would overflow
35+
|
36+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3038

3139
error: any use of this value will cause an error
32-
--> $DIR/const-err-early.rs:6:19
40+
--> $DIR/const-err-early.rs:9:19
3341
|
3442
LL | pub const D: u8 = 42u8 - (42u8 + 1);
3543
| ------------------^^^^^^^^^^^^^^^^^-
3644
| |
3745
| attempt to compute `42_u8 - 43_u8`, which would overflow
46+
|
47+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3849

3950
error: any use of this value will cause an error
40-
--> $DIR/const-err-early.rs:7:19
51+
--> $DIR/const-err-early.rs:11:19
4152
|
4253
LL | pub const E: u8 = [5u8][1];
4354
| ------------------^^^^^^^^-
4455
| |
4556
| index out of bounds: the length is 1 but the index is 1
57+
|
58+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
59+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
4660

4761
error: aborting due to 5 previous errors
4862

src/test/ui/consts/const-err-multi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
pub const A: i8 = -i8::MIN;
44
//~^ ERROR const_err
5+
//~| WARN this was previously accepted by the compiler but is being phased out
56
pub const B: i8 = A;
67
//~^ ERROR const_err
8+
//~| WARN this was previously accepted by the compiler but is being phased out
79
pub const C: u8 = A as u8;
810
//~^ ERROR const_err
11+
//~| WARN this was previously accepted by the compiler but is being phased out
912
pub const D: i8 = 50 - A;
1013
//~^ ERROR const_err
14+
//~| WARN this was previously accepted by the compiler but is being phased out
1115

1216
fn main() {
1317
let _ = (A, B, C, D);

src/test/ui/consts/const-err-multi.stderr

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,41 @@ note: the lint level is defined here
1111
|
1212
LL | #![deny(const_err)]
1313
| ^^^^^^^^^
14+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1416

1517
error: any use of this value will cause an error
16-
--> $DIR/const-err-multi.rs:5:19
18+
--> $DIR/const-err-multi.rs:6:19
1719
|
1820
LL | pub const B: i8 = A;
1921
| ------------------^-
2022
| |
2123
| referenced constant has errors
24+
|
25+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2227

2328
error: any use of this value will cause an error
24-
--> $DIR/const-err-multi.rs:7:19
29+
--> $DIR/const-err-multi.rs:9:19
2530
|
2631
LL | pub const C: u8 = A as u8;
2732
| ------------------^-------
2833
| |
2934
| referenced constant has errors
35+
|
36+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3038

3139
error: any use of this value will cause an error
32-
--> $DIR/const-err-multi.rs:9:24
40+
--> $DIR/const-err-multi.rs:12:24
3341
|
3442
LL | pub const D: i8 = 50 - A;
3543
| -----------------------^-
3644
| |
3745
| referenced constant has errors
46+
|
47+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3849

3950
error: aborting due to 4 previous errors
4051

src/test/ui/consts/const-err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn black_box<T>(_: T) {
1010

1111
const FOO: u8 = [5u8][1];
1212
//~^ WARN any use of this value will cause an error
13+
//~| WARN this was previously accepted by the compiler but is being phased out
1314

1415
fn main() {
1516
black_box((FOO, FOO));

src/test/ui/consts/const-err.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ note: the lint level is defined here
1111
|
1212
LL | #![warn(const_err)]
1313
| ^^^^^^^^^
14+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1416

1517
error[E0080]: erroneous constant used
16-
--> $DIR/const-err.rs:15:16
18+
--> $DIR/const-err.rs:16:16
1719
|
1820
LL | black_box((FOO, FOO));
1921
| ^^^ referenced constant has errors
2022

2123
error[E0080]: erroneous constant used
22-
--> $DIR/const-err.rs:15:21
24+
--> $DIR/const-err.rs:16:21
2325
|
2426
LL | black_box((FOO, FOO));
2527
| ^^^ referenced constant has errors

src/test/ui/consts/const-eval/conditional_array_execution.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const X: u32 = 5;
66
const Y: u32 = 6;
77
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
88
//~^ WARN any use of this value will cause an error
9+
//~| WARN this was previously accepted by the compiler but is being phased out
910

1011
fn main() {
1112
println!("{}", FOO);
1213
//~^ ERROR
1314
//~| WARN erroneous constant used [const_err]
15+
//~| WARN this was previously accepted by the compiler but is being phased out
1416
}

src/test/ui/consts/const-eval/conditional_array_execution.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ note: the lint level is defined here
1111
|
1212
LL | #![warn(const_err)]
1313
| ^^^^^^^^^
14+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1416

1517
error[E0080]: evaluation of constant value failed
16-
--> $DIR/conditional_array_execution.rs:11:20
18+
--> $DIR/conditional_array_execution.rs:12:20
1719
|
1820
LL | println!("{}", FOO);
1921
| ^^^ referenced constant has errors
2022

2123
warning: erroneous constant used
22-
--> $DIR/conditional_array_execution.rs:11:20
24+
--> $DIR/conditional_array_execution.rs:12:20
2325
|
2426
LL | println!("{}", FOO);
2527
| ^^^ referenced constant has errors
28+
|
29+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2631

2732
error: aborting due to previous error; 2 warnings emitted
2833

0 commit comments

Comments
 (0)