Skip to content

Commit e45a17b

Browse files
authored
Unrolled build for rust-lang#120973
Rollup merge of rust-lang#120973 - RalfJung:static_mut_ref, r=compiler-errors allow static_mut_ref in some tests that specifically test mutable statics The lint just distracts from what these tests are about.
2 parents 09d73fa + 6fe4d66 commit e45a17b

15 files changed

+30
-212
lines changed

tests/ui/consts/const_refs_to_static_fail_invalid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
22
// normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
33
#![feature(const_refs_to_static)]
4+
#![allow(static_mut_ref)]
45

56
fn invalid() {
67
static S: i8 = 10;
@@ -38,7 +39,6 @@ fn mutable() {
3839
const C: &i32 = unsafe { &S_MUT };
3940
//~^ERROR: undefined behavior
4041
//~| encountered reference to mutable memory
41-
//~| WARN shared reference of mutable static is discouraged
4242

4343
// This *must not build*, the constant we are matching against
4444
// could change its value!
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
warning: shared reference of mutable static is discouraged
2-
--> $DIR/const_refs_to_static_fail_invalid.rs:38:30
3-
|
4-
LL | const C: &i32 = unsafe { &S_MUT };
5-
| ^^^^^^ shared reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
12-
|
13-
LL | const C: &i32 = unsafe { addr_of!(S_MUT) };
14-
| ~~~~~~~~~~~~~~~
15-
161
error[E0080]: it is undefined behavior to use this value
17-
--> $DIR/const_refs_to_static_fail_invalid.rs:8:5
2+
--> $DIR/const_refs_to_static_fail_invalid.rs:9:5
183
|
194
LL | const C: &bool = unsafe { std::mem::transmute(&S) };
205
| ^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered 0x0a, but expected a boolean
@@ -25,13 +10,13 @@ LL | const C: &bool = unsafe { std::mem::transmute(&S) };
2510
}
2611

2712
error: could not evaluate constant pattern
28-
--> $DIR/const_refs_to_static_fail_invalid.rs:14:9
13+
--> $DIR/const_refs_to_static_fail_invalid.rs:15:9
2914
|
3015
LL | C => {}
3116
| ^
3217

3318
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/const_refs_to_static_fail_invalid.rs:24:5
19+
--> $DIR/const_refs_to_static_fail_invalid.rs:25:5
3520
|
3621
LL | const C: &i8 = unsafe { &S };
3722
| ^^^^^^^^^^^^ constructing invalid value: encountered reference to `extern` static in `const`
@@ -42,13 +27,13 @@ LL | const C: &i8 = unsafe { &S };
4227
}
4328

4429
error: could not evaluate constant pattern
45-
--> $DIR/const_refs_to_static_fail_invalid.rs:30:9
30+
--> $DIR/const_refs_to_static_fail_invalid.rs:31:9
4631
|
4732
LL | C => {}
4833
| ^
4934

5035
error[E0080]: it is undefined behavior to use this value
51-
--> $DIR/const_refs_to_static_fail_invalid.rs:38:5
36+
--> $DIR/const_refs_to_static_fail_invalid.rs:39:5
5237
|
5338
LL | const C: &i32 = unsafe { &S_MUT };
5439
| ^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@@ -64,6 +49,6 @@ error: could not evaluate constant pattern
6449
LL | C => {},
6550
| ^
6651

67-
error: aborting due to 6 previous errors; 1 warning emitted
52+
error: aborting due to 6 previous errors
6853

6954
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#![allow(static_mut_ref)]
2+
13
const C1: &'static mut [usize] = &mut [];
24
//~^ ERROR: mutable references are not allowed
35

46
static mut S: usize = 3;
57
const C2: &'static mut usize = unsafe { &mut S };
68
//~^ ERROR: referencing statics in constants
7-
//~| WARN mutable reference of mutable static is discouraged [static_mut_ref]
89

910
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
warning: mutable reference of mutable static is discouraged
2-
--> $DIR/issue-17718-const-bad-values.rs:5:41
3-
|
4-
LL | const C2: &'static mut usize = unsafe { &mut S };
5-
| ^^^^^^ mutable reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
12-
|
13-
LL | const C2: &'static mut usize = unsafe { addr_of_mut!(S) };
14-
| ~~~~~~~~~~~~~~~
15-
161
error[E0764]: mutable references are not allowed in the final value of constants
17-
--> $DIR/issue-17718-const-bad-values.rs:1:34
2+
--> $DIR/issue-17718-const-bad-values.rs:3:34
183
|
194
LL | const C1: &'static mut [usize] = &mut [];
205
| ^^^^^^^
216

227
error[E0658]: referencing statics in constants is unstable
23-
--> $DIR/issue-17718-const-bad-values.rs:5:46
8+
--> $DIR/issue-17718-const-bad-values.rs:7:46
249
|
2510
LL | const C2: &'static mut usize = unsafe { &mut S };
2611
| ^
@@ -31,7 +16,7 @@ LL | const C2: &'static mut usize = unsafe { &mut S };
3116
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.
3217
= help: to fix this, the value can be extracted to a `const` and then used.
3318

34-
error: aborting due to 2 previous errors; 1 warning emitted
19+
error: aborting due to 2 previous errors
3520

3621
Some errors have detailed explanations: E0658, E0764.
3722
For more information about an error, try `rustc --explain E0658`.

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
warning: shared reference of mutable static is discouraged
2-
--> $DIR/const_refers_to_static_cross_crate.rs:12:14
3-
|
4-
LL | unsafe { &static_cross_crate::ZERO }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
12-
|
13-
LL | unsafe { addr_of!(static_cross_crate::ZERO) }
14-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
161
error[E0080]: it is undefined behavior to use this value
17-
--> $DIR/const_refers_to_static_cross_crate.rs:10:1
2+
--> $DIR/const_refers_to_static_cross_crate.rs:11:1
183
|
194
LL | const SLICE_MUT: &[u8; 1] = {
205
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@@ -79,7 +64,7 @@ LL | U8_MUT3 => true,
7964
warning: skipping const checks
8065
|
8166
help: skipping check for `const_refs_to_static` feature
82-
--> $DIR/const_refers_to_static_cross_crate.rs:12:15
67+
--> $DIR/const_refers_to_static_cross_crate.rs:13:15
8368
|
8469
LL | unsafe { &static_cross_crate::ZERO }
8570
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -99,6 +84,6 @@ help: skipping check for `const_refs_to_static` feature
9984
LL | match static_cross_crate::OPT_ZERO {
10085
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10186

102-
error: aborting due to 8 previous errors; 2 warnings emitted
87+
error: aborting due to 8 previous errors; 1 warning emitted
10388

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

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
warning: shared reference of mutable static is discouraged
2-
--> $DIR/const_refers_to_static_cross_crate.rs:12:14
3-
|
4-
LL | unsafe { &static_cross_crate::ZERO }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
12-
|
13-
LL | unsafe { addr_of!(static_cross_crate::ZERO) }
14-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
161
error[E0080]: it is undefined behavior to use this value
17-
--> $DIR/const_refers_to_static_cross_crate.rs:10:1
2+
--> $DIR/const_refers_to_static_cross_crate.rs:11:1
183
|
194
LL | const SLICE_MUT: &[u8; 1] = {
205
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@@ -79,7 +64,7 @@ LL | U8_MUT3 => true,
7964
warning: skipping const checks
8065
|
8166
help: skipping check for `const_refs_to_static` feature
82-
--> $DIR/const_refers_to_static_cross_crate.rs:12:15
67+
--> $DIR/const_refers_to_static_cross_crate.rs:13:15
8368
|
8469
LL | unsafe { &static_cross_crate::ZERO }
8570
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -99,6 +84,6 @@ help: skipping check for `const_refs_to_static` feature
9984
LL | match static_cross_crate::OPT_ZERO {
10085
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10186

102-
error: aborting due to 8 previous errors; 2 warnings emitted
87+
error: aborting due to 8 previous errors; 1 warning emitted
10388

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

tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// aux-build:static_cross_crate.rs
33
// stderr-per-bitwidth
44
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
5+
#![allow(static_mut_ref)]
56

67
extern crate static_cross_crate;
78

@@ -10,7 +11,6 @@ extern crate static_cross_crate;
1011
const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior
1112
//~| encountered reference to mutable memory
1213
unsafe { &static_cross_crate::ZERO }
13-
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
1414
};
1515

1616
const U8_MUT: &u8 = { //~ ERROR undefined behavior
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// build-pass (FIXME(62277): could be check-pass?)
2+
#![allow(static_mut_ref)]
23

34
static mut STDERR_BUFFER_SPACE: [u8; 42] = [0u8; 42];
45

56
pub static mut STDERR_BUFFER: *mut [u8] = unsafe { &mut STDERR_BUFFER_SPACE };
6-
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
77

88
fn main() {}

tests/ui/consts/static_mut_containing_mut_ref.stderr

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
warning: mutable reference of mutable static is discouraged
2-
--> $DIR/static_mut_containing_mut_ref2.rs:8:6
3-
|
4-
LL | *(&mut STDERR_BUFFER_SPACE) = 42;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
12-
|
13-
LL | *addr_of_mut!(STDERR_BUFFER_SPACE) = 42;
14-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
161
error[E0080]: could not evaluate static initializer
172
--> $DIR/static_mut_containing_mut_ref2.rs:8:5
183
|
194
LL | *(&mut STDERR_BUFFER_SPACE) = 42;
205
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
216

22-
error: aborting due to 1 previous error; 1 warning emitted
7+
error: aborting due to 1 previous error
238

249
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: stock mut_refs
2-
2+
#![allow(static_mut_ref)]
33
#![cfg_attr(mut_refs, feature(const_mut_refs))]
44

55
static mut STDERR_BUFFER_SPACE: u8 = 0;
@@ -8,8 +8,6 @@ pub static mut STDERR_BUFFER: () = unsafe {
88
*(&mut STDERR_BUFFER_SPACE) = 42;
99
//[mut_refs]~^ ERROR could not evaluate static initializer
1010
//[stock]~^^ ERROR mutation through a reference is not allowed in statics
11-
//[mut_refs]~^^^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
12-
//[stock]~^^^^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
1311
};
1412

1513
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
warning: mutable reference of mutable static is discouraged
2-
--> $DIR/static_mut_containing_mut_ref2.rs:8:6
3-
|
4-
LL | *(&mut STDERR_BUFFER_SPACE) = 42;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
12-
|
13-
LL | *addr_of_mut!(STDERR_BUFFER_SPACE) = 42;
14-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
161
error[E0658]: mutation through a reference is not allowed in statics
172
--> $DIR/static_mut_containing_mut_ref2.rs:8:5
183
|
@@ -23,6 +8,6 @@ LL | *(&mut STDERR_BUFFER_SPACE) = 42;
238
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
249
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2510

26-
error: aborting due to 1 previous error; 1 warning emitted
11+
error: aborting due to 1 previous error
2712

2813
For more information about this error, try `rustc --explain E0658`.

tests/ui/thread-local/thread-local-static.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
#![feature(thread_local)]
44
#![feature(const_swap)]
5+
#![allow(static_mut_ref)]
56

67
#[thread_local]
78
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
89
const fn g(x: &mut [u32; 8]) {
910
//~^ ERROR mutable references are not allowed
1011
std::mem::swap(x, &mut STATIC_VAR_2)
11-
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
12-
//~^^ ERROR thread-local statics cannot be accessed
12+
//~^ ERROR thread-local statics cannot be accessed
1313
//~| ERROR mutable references are not allowed
1414
//~| ERROR use of mutable static is unsafe
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
warning: mutable reference of mutable static is discouraged
2-
--> $DIR/thread-local-static.rs:10:23
3-
|
4-
LL | std::mem::swap(x, &mut STATIC_VAR_2)
5-
| ^^^^^^^^^^^^^^^^^ mutable reference of mutable static
6-
|
7-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8-
= note: reference of mutable static is a hard error from 2024 edition
9-
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10-
= note: `#[warn(static_mut_ref)]` on by default
11-
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
12-
|
13-
LL | std::mem::swap(x, addr_of_mut!(STATIC_VAR_2))
14-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
161
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
17-
--> $DIR/thread-local-static.rs:10:28
2+
--> $DIR/thread-local-static.rs:11:28
183
|
194
LL | std::mem::swap(x, &mut STATIC_VAR_2)
205
| ^^^^^^^^^^^^ use of mutable static
216
|
227
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
238

249
error[E0658]: mutable references are not allowed in constant functions
25-
--> $DIR/thread-local-static.rs:8:12
10+
--> $DIR/thread-local-static.rs:9:12
2611
|
2712
LL | const fn g(x: &mut [u32; 8]) {
2813
| ^
@@ -32,13 +17,13 @@ LL | const fn g(x: &mut [u32; 8]) {
3217
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3318

3419
error[E0625]: thread-local statics cannot be accessed at compile-time
35-
--> $DIR/thread-local-static.rs:10:28
20+
--> $DIR/thread-local-static.rs:11:28
3621
|
3722
LL | std::mem::swap(x, &mut STATIC_VAR_2)
3823
| ^^^^^^^^^^^^
3924

4025
error[E0658]: mutable references are not allowed in constant functions
41-
--> $DIR/thread-local-static.rs:10:23
26+
--> $DIR/thread-local-static.rs:11:23
4227
|
4328
LL | std::mem::swap(x, &mut STATIC_VAR_2)
4429
| ^^^^^^^^^^^^^^^^^
@@ -47,7 +32,7 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
4732
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
4833
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4934

50-
error: aborting due to 4 previous errors; 1 warning emitted
35+
error: aborting due to 4 previous errors
5136

5237
Some errors have detailed explanations: E0133, E0625, E0658.
5338
For more information about an error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)