Skip to content

Commit 9cf28f2

Browse files
pnkfelixcuviper
authored andcommitted
Added deny(const_eval_mutable_ptr_in_final_value) attribute to all tests that were expecting the hard error for it.
I attempted to do this in a manner that preserved the line numbers to reduce the review effort on the resulting diff, but we still have to deal with the ramifications of how a future-incompat lint behaves compared to a hard-error (in terms of its impact on the diagnostic output). (cherry picked from commit 1c3424b)
1 parent 6c06ca0 commit 9cf28f2

8 files changed

+916
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#![feature(core_intrinsics)]
22
#![feature(const_heap)]
33
#![feature(const_mut_refs)]
4+
#![deny(const_eval_mutable_ptr_in_final_value)]
45
use std::intrinsics;
56

67
const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
78
//~^ error: mutable pointer in final value of constant
9+
//~| WARNING this was previously accepted by the compiler
810

911
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
error: encountered mutable pointer in final value of constant
2-
--> $DIR/alloc_intrinsic_untyped.rs:6:1
2+
--> $DIR/alloc_intrinsic_untyped.rs:7:1
33
|
44
LL | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
55
| ^^^^^^^^^^^^^^^^^^^
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 #122153 <https://github.com/rust-lang/rust/issues/122153>
9+
note: the lint level is defined here
10+
--> $DIR/alloc_intrinsic_untyped.rs:4:9
11+
|
12+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
614

715
error: aborting due to 1 previous error
816

17+
Future incompatibility report: Future breakage diagnostic:
18+
error: encountered mutable pointer in final value of constant
19+
--> $DIR/alloc_intrinsic_untyped.rs:7:1
20+
|
21+
LL | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
22+
| ^^^^^^^^^^^^^^^^^^^
23+
|
24+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
25+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
26+
note: the lint level is defined here
27+
--> $DIR/alloc_intrinsic_untyped.rs:4:9
28+
|
29+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+

tests/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr

+235-35
Large diffs are not rendered by default.

tests/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr

+235-35
Large diffs are not rendered by default.

tests/ui/consts/miri_unleashed/mutable_references_err.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// stderr-per-bitwidth
22
// compile-flags: -Zunleash-the-miri-inside-of-you
33
#![allow(invalid_reference_casting, static_mut_refs)]
4-
4+
#![deny(const_eval_mutable_ptr_in_final_value)]
55
use std::cell::UnsafeCell;
66
use std::sync::atomic::*;
77

@@ -16,6 +16,8 @@ unsafe impl Sync for Meh {}
1616
// all allocs interned here will be marked immutable.
1717
const MUH: Meh = Meh {
1818
//~^ ERROR encountered mutable pointer in final value of constant
19+
//~| WARNING this was previously accepted by the compiler
20+
//~| ERROR: it is undefined behavior to use this value
1921
x: &UnsafeCell::new(42),
2022
};
2123

@@ -27,14 +29,19 @@ unsafe impl Sync for Synced {}
2729
// Make sure we also catch this behind a type-erased `dyn Trait` reference.
2830
const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
2931
//~^ ERROR: mutable pointer in final value
32+
//~| WARNING this was previously accepted by the compiler
33+
//~| ERROR it is undefined behavior to use this value
3034

3135
// Make sure we also catch mutable references in values that shouldn't have them.
3236
static mut FOO: i32 = 0;
3337
const SUBTLE: &mut i32 = unsafe { &mut FOO };
3438
//~^ ERROR: it is undefined behavior to use this value
3539
//~| static
40+
3641
const BLUNT: &mut i32 = &mut 42;
3742
//~^ ERROR: mutable pointer in final value
43+
//~| WARNING this was previously accepted by the compiler
44+
//~| ERROR it is undefined behavior to use this value
3845

3946
// Check for mutable references to read-only memory.
4047
static READONLY: i32 = 0;
@@ -55,10 +62,15 @@ const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
5562

5663
const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
5764
//~^ ERROR: mutable pointer in final value
65+
//~| WARNING this was previously accepted by the compiler
66+
5867
const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
5968
//~^ ERROR: mutable pointer in final value
69+
//~| WARNING this was previously accepted by the compiler
70+
6071
const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
6172
//~^ ERROR: mutable pointer in final value
73+
//~| WARNING this was previously accepted by the compiler
6274

6375
struct SyncPtr<T> {
6476
x: *const T,
@@ -71,10 +83,15 @@ unsafe impl<T> Sync for SyncPtr<T> {}
7183
// (Also see `static-no-inner-mut` for similar tests on `static`.)
7284
const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
7385
//~^ ERROR mutable pointer in final value
86+
//~| WARNING this was previously accepted by the compiler
87+
7488
const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
7589
//~^ ERROR mutable pointer in final value
90+
//~| WARNING this was previously accepted by the compiler
91+
7692
const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
7793
//~^ ERROR mutable pointer in final value
94+
//~| WARNING this was previously accepted by the compiler
7895

7996
fn main() {
8097
unsafe {

tests/ui/consts/miri_unleashed/static-no-inner-mut.32bit.stderr

+189-13
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,112 @@ error: encountered mutable pointer in final value of static
33
|
44
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
55
| ^^^^^^^^^^^^^^^^^^^^^^
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 #122153 <https://github.com/rust-lang/rust/issues/122153>
9+
note: the lint level is defined here
10+
--> $DIR/static-no-inner-mut.rs:6:9
11+
|
12+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error[E0080]: it is undefined behavior to use this value
16+
--> $DIR/static-no-inner-mut.rs:9:1
17+
|
18+
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
19+
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.v: encountered `UnsafeCell` in read-only memory
20+
|
21+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
22+
= note: the raw bytes of the constant (size: 4, align: 4) {
23+
╾ALLOC0╼ │ ╾──╼
24+
}
625

726
error: encountered mutable pointer in final value of static
8-
--> $DIR/static-no-inner-mut.rs:10:1
27+
--> $DIR/static-no-inner-mut.rs:14:1
928
|
1029
LL | static REFMUT: &mut i32 = &mut 0;
1130
| ^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
33+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
34+
35+
error[E0080]: it is undefined behavior to use this value
36+
--> $DIR/static-no-inner-mut.rs:14:1
37+
|
38+
LL | static REFMUT: &mut i32 = &mut 0;
39+
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
40+
|
41+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
42+
= note: the raw bytes of the constant (size: 4, align: 4) {
43+
╾ALLOC1╼ │ ╾──╼
44+
}
1245

1346
error: encountered mutable pointer in final value of static
14-
--> $DIR/static-no-inner-mut.rs:13:1
47+
--> $DIR/static-no-inner-mut.rs:20:1
1548
|
1649
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
1750
| ^^^^^^^^^^^^^^^^^^^^^^^
51+
|
52+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
53+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
54+
55+
error[E0080]: it is undefined behavior to use this value
56+
--> $DIR/static-no-inner-mut.rs:20:1
57+
|
58+
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
59+
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.v: encountered `UnsafeCell` in read-only memory
60+
|
61+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
62+
= note: the raw bytes of the constant (size: 4, align: 4) {
63+
╾ALLOC2╼ │ ╾──╼
64+
}
1865

1966
error: encountered mutable pointer in final value of static
20-
--> $DIR/static-no-inner-mut.rs:14:1
67+
--> $DIR/static-no-inner-mut.rs:25:1
2168
|
2269
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
2370
| ^^^^^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
73+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
74+
75+
error[E0080]: it is undefined behavior to use this value
76+
--> $DIR/static-no-inner-mut.rs:25:1
77+
|
78+
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
80+
|
81+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
82+
= note: the raw bytes of the constant (size: 4, align: 4) {
83+
╾ALLOC3╼ │ ╾──╼
84+
}
2485

2586
error: encountered mutable pointer in final value of static
26-
--> $DIR/static-no-inner-mut.rs:29:1
87+
--> $DIR/static-no-inner-mut.rs:43:1
2788
|
2889
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
2990
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
|
92+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
93+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
3094

3195
error: encountered mutable pointer in final value of static
32-
--> $DIR/static-no-inner-mut.rs:31:1
96+
--> $DIR/static-no-inner-mut.rs:47:1
3397
|
3498
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
3599
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100+
|
101+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
102+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
36103

37104
error: encountered mutable pointer in final value of static
38-
--> $DIR/static-no-inner-mut.rs:33:1
105+
--> $DIR/static-no-inner-mut.rs:51:1
39106
|
40107
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
41108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109+
|
110+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
111+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
42112

43113
warning: skipping const checks
44114
|
@@ -48,35 +118,141 @@ help: skipping check that does not even have a feature gate
48118
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
49119
| ^^^^^^^^^^^^^^^^^^^
50120
help: skipping check that does not even have a feature gate
51-
--> $DIR/static-no-inner-mut.rs:10:27
121+
--> $DIR/static-no-inner-mut.rs:14:27
52122
|
53123
LL | static REFMUT: &mut i32 = &mut 0;
54124
| ^^^^^^
55125
help: skipping check that does not even have a feature gate
56-
--> $DIR/static-no-inner-mut.rs:13:56
126+
--> $DIR/static-no-inner-mut.rs:20:56
57127
|
58128
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
59129
| ^^^^
60130
help: skipping check that does not even have a feature gate
61-
--> $DIR/static-no-inner-mut.rs:14:44
131+
--> $DIR/static-no-inner-mut.rs:25:44
62132
|
63133
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
64134
| ^^^^^^^^
65135
help: skipping check that does not even have a feature gate
66-
--> $DIR/static-no-inner-mut.rs:29:52
136+
--> $DIR/static-no-inner-mut.rs:43:52
67137
|
68138
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
69139
| ^^^^^^^^^^^^^^^^^^^
70140
help: skipping check that does not even have a feature gate
71-
--> $DIR/static-no-inner-mut.rs:31:51
141+
--> $DIR/static-no-inner-mut.rs:47:51
72142
|
73143
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
74144
| ^^^^^^^
75145
help: skipping check that does not even have a feature gate
76-
--> $DIR/static-no-inner-mut.rs:33:52
146+
--> $DIR/static-no-inner-mut.rs:51:52
77147
|
78148
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
79149
| ^^^^^^
80150

81-
error: aborting due to 7 previous errors; 1 warning emitted
151+
error: aborting due to 11 previous errors; 1 warning emitted
152+
153+
For more information about this error, try `rustc --explain E0080`.
154+
Future incompatibility report: Future breakage diagnostic:
155+
error: encountered mutable pointer in final value of static
156+
--> $DIR/static-no-inner-mut.rs:9:1
157+
|
158+
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
159+
| ^^^^^^^^^^^^^^^^^^^^^^
160+
|
161+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
162+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
163+
note: the lint level is defined here
164+
--> $DIR/static-no-inner-mut.rs:6:9
165+
|
166+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
167+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
169+
Future breakage diagnostic:
170+
error: encountered mutable pointer in final value of static
171+
--> $DIR/static-no-inner-mut.rs:14:1
172+
|
173+
LL | static REFMUT: &mut i32 = &mut 0;
174+
| ^^^^^^^^^^^^^^^^^^^^^^^
175+
|
176+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
177+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
178+
note: the lint level is defined here
179+
--> $DIR/static-no-inner-mut.rs:6:9
180+
|
181+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
182+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
183+
184+
Future breakage diagnostic:
185+
error: encountered mutable pointer in final value of static
186+
--> $DIR/static-no-inner-mut.rs:20:1
187+
|
188+
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
189+
| ^^^^^^^^^^^^^^^^^^^^^^^
190+
|
191+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
192+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
193+
note: the lint level is defined here
194+
--> $DIR/static-no-inner-mut.rs:6:9
195+
|
196+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
197+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198+
199+
Future breakage diagnostic:
200+
error: encountered mutable pointer in final value of static
201+
--> $DIR/static-no-inner-mut.rs:25:1
202+
|
203+
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
204+
| ^^^^^^^^^^^^^^^^^^^^^^^^
205+
|
206+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
207+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
208+
note: the lint level is defined here
209+
--> $DIR/static-no-inner-mut.rs:6:9
210+
|
211+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
212+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213+
214+
Future breakage diagnostic:
215+
error: encountered mutable pointer in final value of static
216+
--> $DIR/static-no-inner-mut.rs:43:1
217+
|
218+
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
219+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220+
|
221+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
222+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
223+
note: the lint level is defined here
224+
--> $DIR/static-no-inner-mut.rs:6:9
225+
|
226+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
227+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
228+
229+
Future breakage diagnostic:
230+
error: encountered mutable pointer in final value of static
231+
--> $DIR/static-no-inner-mut.rs:47:1
232+
|
233+
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
234+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235+
|
236+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
237+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
238+
note: the lint level is defined here
239+
--> $DIR/static-no-inner-mut.rs:6:9
240+
|
241+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
242+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
243+
244+
Future breakage diagnostic:
245+
error: encountered mutable pointer in final value of static
246+
--> $DIR/static-no-inner-mut.rs:51:1
247+
|
248+
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
249+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250+
|
251+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
252+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
253+
note: the lint level is defined here
254+
--> $DIR/static-no-inner-mut.rs:6:9
255+
|
256+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
257+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82258

0 commit comments

Comments
 (0)