Skip to content

Commit 410d2a2

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 88608f1 commit 410d2a2

7 files changed

+513
-8
lines changed

tests/ui/consts/const-eval/heap/alloc_intrinsic_untyped.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(const_heap)]
33
#![feature(const_mut_refs)]
44
use std::intrinsics;
5-
5+
#[deny(const_eval_mutable_ptr_in_final_value)]
66
const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
77
//~^ error: mutable pointer in final value of constant
88

tests/ui/consts/miri_unleashed/mutable_references.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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

tests/ui/consts/miri_unleashed/mutable_references.stderr

+131-2
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,83 @@ 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
827
--> $DIR/mutable_references.rs:10: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
1436
--> $DIR/mutable_references.rs:15: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
2045
--> $DIR/mutable_references.rs:22: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:22: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
2665
--> $DIR/mutable_references.rs:25: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:25: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
3285
--> $DIR/mutable_references.rs:32:5
@@ -62,6 +115,82 @@ help: skipping check that does not even have a feature gate
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:10: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:15: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:22: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:25: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

+1-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

0 commit comments

Comments
 (0)