Skip to content

Commit ec57c60

Browse files
committed
Auto merge of #86194 - RalfJung:const-ub-hard-error, r=oli-obk
make UB during CTFE a hard error This is a next step for #71800. `const_err` has been a future-incompatibility lint for 4 months now since #80394 (and err-by-default for many years before that), so I think we could try making it a proper hard error at least in some situations. I didn't yet adjust the tests, since I first want to gauge the fall-out via crater. Cc `@rust-lang/wg-const-eval`
2 parents ce1d561 + 7475661 commit ec57c60

25 files changed

+336
-859
lines changed

compiler/rustc_middle/src/mir/interpret/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ impl InterpError<'_> {
525525
use InterpError::*;
526526
match *self {
527527
MachineStop(ref err) => err.is_hard_err(),
528+
InterpError::UndefinedBehavior(_) => true,
528529
_ => false,
529530
}
530531
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use std::mem;
55
// Make sure we error with the right kind of error on a too large slice.
66
const TEST: () = { unsafe {
77
let slice: *const [u8] = mem::transmute((1usize, usize::MAX));
8-
let _val = &*slice; //~ ERROR: any use of this value will cause an error
8+
let _val = &*slice; //~ ERROR: evaluation of constant value failed
99
//~| slice is bigger than largest supported object
10-
//~| WARN this was previously accepted by the compiler but is being phased out
1110
} };
1211

1312
fn main() {}
+4-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
error: any use of this value will cause an error
1+
error[E0080]: evaluation of constant value failed
22
--> $DIR/dangling.rs:8:16
33
|
4-
LL | / const TEST: () = { unsafe {
5-
LL | | let slice: *const [u8] = mem::transmute((1usize, usize::MAX));
6-
LL | | let _val = &*slice;
7-
| | ^^^^^^^ invalid metadata in wide pointer: slice is bigger than largest supported object
8-
LL | |
9-
LL | |
10-
LL | | } };
11-
| |____-
12-
|
13-
= note: `#[deny(const_err)]` on by default
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>
4+
LL | let _val = &*slice;
5+
| ^^^^^^^ invalid metadata in wide pointer: slice is bigger than largest supported object
166

177
error: aborting due to previous error
188

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

src/test/ui/consts/const-eval/heap/alloc_intrinsic_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const FOO: i32 = foo();
88
const fn foo() -> i32 {
99
unsafe {
1010
let _ = intrinsics::const_allocate(4, 3) as * mut i32;
11-
//~^ error: any use of this value will cause an error [const_err]
12-
//~| WARN this was previously accepted by the compiler but is being phased out
11+
//~^ error: evaluation of constant value failed
1312
}
1413
1
1514

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
error: any use of this value will cause an error
1+
error[E0080]: evaluation of constant value failed
22
--> $DIR/alloc_intrinsic_errors.rs:10:17
33
|
44
LL | const FOO: i32 = foo();
5-
| -----------------------
5+
| ----- inside `FOO` at $DIR/alloc_intrinsic_errors.rs:7:18
66
...
77
LL | let _ = intrinsics::const_allocate(4, 3) as * mut i32;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
| |
1010
| align has to be a power of 2, `3` is not a power of 2
1111
| inside `foo` at $DIR/alloc_intrinsic_errors.rs:10:17
12-
| inside `FOO` at $DIR/alloc_intrinsic_errors.rs:7:18
13-
|
14-
= note: `#[deny(const_err)]` on by default
15-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1712

1813
error: aborting due to previous error
1914

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

src/test/ui/consts/const-eval/issue-49296.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const fn wat(x: u64) -> &'static u64 {
1717
unsafe { transmute(&x) }
1818
}
1919
const X: u64 = *wat(42);
20-
//~^ ERROR any use of this value will cause an error
21-
//~| WARN this was previously accepted by the compiler but is being phased out
20+
//~^ ERROR evaluation of constant value failed
2221

2322
fn main() {
2423
println!("{}", X);
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
error: any use of this value will cause an error
1+
error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-49296.rs:19:16
33
|
44
LL | const X: u64 = *wat(42);
5-
| ---------------^^^^^^^^-
6-
| |
7-
| pointer to alloc1 was dereferenced after this allocation got freed
8-
|
9-
= 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>
5+
| ^^^^^^^^ pointer to alloc1 was dereferenced after this allocation got freed
126

137
error: aborting due to previous error
148

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

src/test/ui/consts/const-eval/ub-incorrect-vtable.32bit.stderr

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
error: any use of this value will cause an error
1+
error[E0080]: evaluation of constant value failed
22
--> $DIR/ub-incorrect-vtable.rs:19:14
33
|
4-
LL | / const INVALID_VTABLE_ALIGNMENT: &dyn Trait =
5-
LL | | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
6-
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
7-
| |
8-
| invalid vtable: alignment `1000` is not a power of 2
9-
|
10-
= note: `#[deny(const_err)]` on by default
11-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
4+
LL | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid vtable: alignment `1000` is not a power of 2
136

14-
error: any use of this value will cause an error
15-
--> $DIR/ub-incorrect-vtable.rs:25:14
16-
|
17-
LL | / const INVALID_VTABLE_SIZE: &dyn Trait =
18-
LL | | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
19-
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
20-
| |
21-
| invalid vtable: size is bigger than largest supported object
7+
error[E0080]: evaluation of constant value failed
8+
--> $DIR/ub-incorrect-vtable.rs:24:14
229
|
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>
10+
LL | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid vtable: size is bigger than largest supported object
2512

2613
error[E0080]: it is undefined behavior to use this value
27-
--> $DIR/ub-incorrect-vtable.rs:36:1
14+
--> $DIR/ub-incorrect-vtable.rs:34:1
2815
|
2916
LL | / const INVALID_VTABLE_ALIGNMENT_UB: W<&dyn Trait> =
3017
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1usize, 1000usize))) };
@@ -36,7 +23,7 @@ LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1us
3623
}
3724

3825
error[E0080]: it is undefined behavior to use this value
39-
--> $DIR/ub-incorrect-vtable.rs:41:1
26+
--> $DIR/ub-incorrect-vtable.rs:39:1
4027
|
4128
LL | / const INVALID_VTABLE_SIZE_UB: W<&dyn Trait> =
4229
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), usize::MAX, 1usize))) };

src/test/ui/consts/const-eval/ub-incorrect-vtable.64bit.stderr

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
error: any use of this value will cause an error
1+
error[E0080]: evaluation of constant value failed
22
--> $DIR/ub-incorrect-vtable.rs:19:14
33
|
4-
LL | / const INVALID_VTABLE_ALIGNMENT: &dyn Trait =
5-
LL | | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
6-
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
7-
| |
8-
| invalid vtable: alignment `1000` is not a power of 2
9-
|
10-
= note: `#[deny(const_err)]` on by default
11-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
4+
LL | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid vtable: alignment `1000` is not a power of 2
136

14-
error: any use of this value will cause an error
15-
--> $DIR/ub-incorrect-vtable.rs:25:14
16-
|
17-
LL | / const INVALID_VTABLE_SIZE: &dyn Trait =
18-
LL | | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
19-
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
20-
| |
21-
| invalid vtable: size is bigger than largest supported object
7+
error[E0080]: evaluation of constant value failed
8+
--> $DIR/ub-incorrect-vtable.rs:24:14
229
|
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>
10+
LL | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid vtable: size is bigger than largest supported object
2512

2613
error[E0080]: it is undefined behavior to use this value
27-
--> $DIR/ub-incorrect-vtable.rs:36:1
14+
--> $DIR/ub-incorrect-vtable.rs:34:1
2815
|
2916
LL | / const INVALID_VTABLE_ALIGNMENT_UB: W<&dyn Trait> =
3017
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1usize, 1000usize))) };
@@ -36,7 +23,7 @@ LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1us
3623
}
3724

3825
error[E0080]: it is undefined behavior to use this value
39-
--> $DIR/ub-incorrect-vtable.rs:41:1
26+
--> $DIR/ub-incorrect-vtable.rs:39:1
4027
|
4128
LL | / const INVALID_VTABLE_SIZE_UB: W<&dyn Trait> =
4229
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), usize::MAX, 1usize))) };

src/test/ui/consts/const-eval/ub-incorrect-vtable.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ trait Trait {}
1717

1818
const INVALID_VTABLE_ALIGNMENT: &dyn Trait =
1919
unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
20-
//~^ ERROR any use of this value will cause an error
21-
//~| WARNING this was previously accepted by the compiler
20+
//~^ ERROR evaluation of constant value failed
2221
//~| invalid vtable: alignment `1000` is not a power of 2
2322

2423
const INVALID_VTABLE_SIZE: &dyn Trait =
2524
unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
26-
//~^ ERROR any use of this value will cause an error
27-
//~| WARNING this was previously accepted by the compiler
25+
//~^ ERROR evaluation of constant value failed
2826
//~| invalid vtable: size is bigger than largest supported object
2927

3028
#[repr(transparent)]

src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr

+8-23
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
99
00 00 00 00 │ ....
1010
}
1111

12-
error: any use of this value will cause an error
12+
error[E0080]: evaluation of constant value failed
1313
--> $DIR/ub-nonnull.rs:19:30
1414
|
15-
LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
16-
LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
17-
LL | | // Use address-of-element for pointer arithmetic. This could wrap around to null!
18-
LL | | let out_of_bounds_ptr = &ptr[255];
19-
| | ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
20-
LL | |
21-
LL | | mem::transmute(out_of_bounds_ptr)
22-
LL | | } };
23-
| |____-
24-
|
25-
note: the lint level is defined here
26-
--> $DIR/ub-nonnull.rs:15:8
27-
|
28-
LL | #[deny(const_err)] // this triggers a `const_err` so validation does not even happen
29-
| ^^^^^^^^^
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
15+
LL | let out_of_bounds_ptr = &ptr[255];
16+
| ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
3217

3318
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-nonnull.rs:24:1
19+
--> $DIR/ub-nonnull.rs:23:1
3520
|
3621
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
3722
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -42,7 +27,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
4227
}
4328

4429
error[E0080]: it is undefined behavior to use this value
45-
--> $DIR/ub-nonnull.rs:26:1
30+
--> $DIR/ub-nonnull.rs:25:1
4631
|
4732
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
4833
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -53,7 +38,7 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
5338
}
5439

5540
error[E0080]: it is undefined behavior to use this value
56-
--> $DIR/ub-nonnull.rs:34:1
41+
--> $DIR/ub-nonnull.rs:33:1
5742
|
5843
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
5944
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
@@ -64,7 +49,7 @@ LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
6449
}
6550

6651
error[E0080]: it is undefined behavior to use this value
67-
--> $DIR/ub-nonnull.rs:42:1
52+
--> $DIR/ub-nonnull.rs:41:1
6853
|
6954
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7055
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
@@ -75,7 +60,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7560
}
7661

7762
error[E0080]: it is undefined behavior to use this value
78-
--> $DIR/ub-nonnull.rs:48:1
63+
--> $DIR/ub-nonnull.rs:47:1
7964
|
8065
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
8166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30

src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr

+8-23
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
99
00 00 00 00 00 00 00 00 │ ........
1010
}
1111

12-
error: any use of this value will cause an error
12+
error[E0080]: evaluation of constant value failed
1313
--> $DIR/ub-nonnull.rs:19:30
1414
|
15-
LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
16-
LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
17-
LL | | // Use address-of-element for pointer arithmetic. This could wrap around to null!
18-
LL | | let out_of_bounds_ptr = &ptr[255];
19-
| | ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
20-
LL | |
21-
LL | | mem::transmute(out_of_bounds_ptr)
22-
LL | | } };
23-
| |____-
24-
|
25-
note: the lint level is defined here
26-
--> $DIR/ub-nonnull.rs:15:8
27-
|
28-
LL | #[deny(const_err)] // this triggers a `const_err` so validation does not even happen
29-
| ^^^^^^^^^
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
15+
LL | let out_of_bounds_ptr = &ptr[255];
16+
| ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
3217

3318
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-nonnull.rs:24:1
19+
--> $DIR/ub-nonnull.rs:23:1
3520
|
3621
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
3722
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -42,7 +27,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
4227
}
4328

4429
error[E0080]: it is undefined behavior to use this value
45-
--> $DIR/ub-nonnull.rs:26:1
30+
--> $DIR/ub-nonnull.rs:25:1
4631
|
4732
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
4833
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -53,7 +38,7 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
5338
}
5439

5540
error[E0080]: it is undefined behavior to use this value
56-
--> $DIR/ub-nonnull.rs:34:1
41+
--> $DIR/ub-nonnull.rs:33:1
5742
|
5843
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
5944
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
@@ -64,7 +49,7 @@ LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
6449
}
6550

6651
error[E0080]: it is undefined behavior to use this value
67-
--> $DIR/ub-nonnull.rs:42:1
52+
--> $DIR/ub-nonnull.rs:41:1
6853
|
6954
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7055
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
@@ -75,7 +60,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7560
}
7661

7762
error[E0080]: it is undefined behavior to use this value
78-
--> $DIR/ub-nonnull.rs:48:1
63+
--> $DIR/ub-nonnull.rs:47:1
7964
|
8065
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
8166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30

src/test/ui/consts/const-eval/ub-nonnull.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
1616
const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
1717
let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
1818
// Use address-of-element for pointer arithmetic. This could wrap around to null!
19-
let out_of_bounds_ptr = &ptr[255]; //~ ERROR any use of this value will cause an error
20-
//~| WARN this was previously accepted by the compiler but is being phased out
19+
let out_of_bounds_ptr = &ptr[255]; //~ ERROR evaluation of constant value failed
2120
mem::transmute(out_of_bounds_ptr)
2221
} };
2322

0 commit comments

Comments
 (0)