Skip to content

Commit 1c3424b

Browse files
committed
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).
1 parent f86b46a commit 1c3424b

8 files changed

+634
-60
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.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
//@ compile-flags: -Zunleash-the-miri-inside-of-you
2-
2+
#![deny(const_eval_mutable_ptr_in_final_value)]
33
use std::cell::UnsafeCell;
44

55
// a test demonstrating what things we could allow with a smarter const qualification
66

77
static FOO: &&mut u32 = &&mut 42;
88
//~^ ERROR encountered mutable pointer in final value of static
9+
//~| WARNING this was previously accepted by the compiler
10+
//~| ERROR it is undefined behavior to use this value
911

1012
static BAR: &mut () = &mut ();
1113
//~^ ERROR encountered mutable pointer in final value of static
14+
//~| WARNING this was previously accepted by the compiler
1215

1316
struct Foo<T>(T);
1417

1518
static BOO: &mut Foo<()> = &mut Foo(());
1619
//~^ ERROR encountered mutable pointer in final value of static
20+
//~| WARNING this was previously accepted by the compiler
1721

1822
struct Meh {
1923
x: &'static UnsafeCell<i32>,
2024
}
2125
unsafe impl Sync for Meh {}
2226
static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
2327
//~^ ERROR encountered mutable pointer in final value of static
28+
//~| WARNING this was previously accepted by the compiler
29+
//~| ERROR it is undefined behavior to use this value
2430

2531
static OH_YES: &mut i32 = &mut 42;
2632
//~^ ERROR encountered mutable pointer in final value of static
33+
//~| WARNING this was previously accepted by the compiler
34+
//~| ERROR it is undefined behavior to use this value
2735

2836
fn main() {
2937
unsafe {

tests/ui/consts/miri_unleashed/mutable_references.stderr

+140-11
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,86 @@ error: encountered mutable pointer in final value of static
33
|
44
LL | static FOO: &&mut u32 = &&mut 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/mutable_references.rs:2: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/mutable_references.rs:7:1
17+
|
18+
LL | static FOO: &&mut u32 = &&mut 42;
19+
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered mutable reference or box pointing to 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: 8, align: 8) {
23+
╾ALLOC0<imm>╼ │ ╾──────╼
24+
}
625

726
error: encountered mutable pointer in final value of static
8-
--> $DIR/mutable_references.rs:10:1
27+
--> $DIR/mutable_references.rs:12:1
928
|
1029
LL | static BAR: &mut () = &mut ();
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>
1234

1335
error: encountered mutable pointer in final value of static
14-
--> $DIR/mutable_references.rs:15:1
36+
--> $DIR/mutable_references.rs:18:1
1537
|
1638
LL | static BOO: &mut Foo<()> = &mut Foo(());
1739
| ^^^^^^^^^^^^^^^^^^^^^^^^
40+
|
41+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
42+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
1843

1944
error: encountered mutable pointer in final value of static
20-
--> $DIR/mutable_references.rs:22:1
45+
--> $DIR/mutable_references.rs:26:1
2146
|
2247
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
2348
| ^^^^^^^^^^^^^^^
49+
|
50+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
52+
53+
error[E0080]: it is undefined behavior to use this value
54+
--> $DIR/mutable_references.rs:26:1
55+
|
56+
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
57+
| ^^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in read-only memory
58+
|
59+
= 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.
60+
= note: the raw bytes of the constant (size: 8, align: 8) {
61+
╾ALLOC1╼ │ ╾──────╼
62+
}
2463

2564
error: encountered mutable pointer in final value of static
26-
--> $DIR/mutable_references.rs:25:1
65+
--> $DIR/mutable_references.rs:31:1
2766
|
2867
LL | static OH_YES: &mut i32 = &mut 42;
2968
| ^^^^^^^^^^^^^^^^^^^^^^^
69+
|
70+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
71+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
72+
73+
error[E0080]: it is undefined behavior to use this value
74+
--> $DIR/mutable_references.rs:31:1
75+
|
76+
LL | static OH_YES: &mut i32 = &mut 42;
77+
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
78+
|
79+
= 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.
80+
= note: the raw bytes of the constant (size: 8, align: 8) {
81+
╾ALLOC2╼ │ ╾──────╼
82+
}
3083

3184
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
32-
--> $DIR/mutable_references.rs:32:5
85+
--> $DIR/mutable_references.rs:40:5
3386
|
3487
LL | *OH_YES = 99;
3588
| ^^^^^^^^^^^^ cannot assign
@@ -42,26 +95,102 @@ help: skipping check that does not even have a feature gate
4295
LL | static FOO: &&mut u32 = &&mut 42;
4396
| ^^^^^^^
4497
help: skipping check that does not even have a feature gate
45-
--> $DIR/mutable_references.rs:10:23
98+
--> $DIR/mutable_references.rs:12:23
4699
|
47100
LL | static BAR: &mut () = &mut ();
48101
| ^^^^^^^
49102
help: skipping check that does not even have a feature gate
50-
--> $DIR/mutable_references.rs:15:28
103+
--> $DIR/mutable_references.rs:18:28
51104
|
52105
LL | static BOO: &mut Foo<()> = &mut Foo(());
53106
| ^^^^^^^^^^^^
54107
help: skipping check that does not even have a feature gate
55-
--> $DIR/mutable_references.rs:22:28
108+
--> $DIR/mutable_references.rs:26:28
56109
|
57110
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
58111
| ^^^^^^^^^^^^^^^^^^^^
59112
help: skipping check that does not even have a feature gate
60-
--> $DIR/mutable_references.rs:25:27
113+
--> $DIR/mutable_references.rs:31:27
61114
|
62115
LL | static OH_YES: &mut i32 = &mut 42;
63116
| ^^^^^^^
64117

65-
error: aborting due to 6 previous errors; 1 warning emitted
118+
error: aborting due to 9 previous errors; 1 warning emitted
119+
120+
Some errors have detailed explanations: E0080, E0594.
121+
For more information about an error, try `rustc --explain E0080`.
122+
Future incompatibility report: Future breakage diagnostic:
123+
error: encountered mutable pointer in final value of static
124+
--> $DIR/mutable_references.rs:7:1
125+
|
126+
LL | static FOO: &&mut u32 = &&mut 42;
127+
| ^^^^^^^^^^^^^^^^^^^^^
128+
|
129+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
130+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
131+
note: the lint level is defined here
132+
--> $DIR/mutable_references.rs:2:9
133+
|
134+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
135+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136+
137+
Future breakage diagnostic:
138+
error: encountered mutable pointer in final value of static
139+
--> $DIR/mutable_references.rs:12:1
140+
|
141+
LL | static BAR: &mut () = &mut ();
142+
| ^^^^^^^^^^^^^^^^^^^
143+
|
144+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
145+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
146+
note: the lint level is defined here
147+
--> $DIR/mutable_references.rs:2:9
148+
|
149+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
150+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+
152+
Future breakage diagnostic:
153+
error: encountered mutable pointer in final value of static
154+
--> $DIR/mutable_references.rs:18:1
155+
|
156+
LL | static BOO: &mut Foo<()> = &mut Foo(());
157+
| ^^^^^^^^^^^^^^^^^^^^^^^^
158+
|
159+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
160+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
161+
note: the lint level is defined here
162+
--> $DIR/mutable_references.rs:2:9
163+
|
164+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
167+
Future breakage diagnostic:
168+
error: encountered mutable pointer in final value of static
169+
--> $DIR/mutable_references.rs:26:1
170+
|
171+
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
172+
| ^^^^^^^^^^^^^^^
173+
|
174+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
176+
note: the lint level is defined here
177+
--> $DIR/mutable_references.rs:2:9
178+
|
179+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
180+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181+
182+
Future breakage diagnostic:
183+
error: encountered mutable pointer in final value of static
184+
--> $DIR/mutable_references.rs:31:1
185+
|
186+
LL | static OH_YES: &mut i32 = &mut 42;
187+
| ^^^^^^^^^^^^^^^^^^^^^^^
188+
|
189+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
190+
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
191+
note: the lint level is defined here
192+
--> $DIR/mutable_references.rs:2:9
193+
|
194+
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
195+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66196

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

tests/ui/consts/miri_unleashed/mutable_references_err.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
33
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
44
#![allow(invalid_reference_casting, static_mut_refs)]
5-
5+
#![deny(const_eval_mutable_ptr_in_final_value)]
66
use std::cell::UnsafeCell;
77
use std::sync::atomic::*;
88

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

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

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

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

5764
const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
5865
//~^ ERROR: mutable pointer in final value
66+
//~| WARNING this was previously accepted by the compiler
67+
5968
const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
6069
//~^ ERROR: mutable pointer in final value
70+
//~| WARNING this was previously accepted by the compiler
71+
6172
const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
6273
//~^ ERROR: mutable pointer in final value
74+
//~| WARNING this was previously accepted by the compiler
6375

6476
struct SyncPtr<T> {
6577
x: *const T,
@@ -72,10 +84,15 @@ unsafe impl<T> Sync for SyncPtr<T> {}
7284
// (Also see `static-no-inner-mut` for similar tests on `static`.)
7385
const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
7486
//~^ ERROR mutable pointer in final value
87+
//~| WARNING this was previously accepted by the compiler
88+
7589
const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
7690
//~^ ERROR mutable pointer in final value
91+
//~| WARNING this was previously accepted by the compiler
92+
7793
const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
7894
//~^ ERROR mutable pointer in final value
95+
//~| WARNING this was previously accepted by the compiler
7996

8097
fn main() {
8198
unsafe {

0 commit comments

Comments
 (0)