Skip to content

Commit d17b7f6

Browse files
authored
Unrolled build for rust-lang#140056
Rollup merge of rust-lang#140056 - yuk1ty:fix-static-mut-error-message, r=jieyouxu Fix a wrong error message in 2024 edition Fixes rust-lang#139952
2 parents 7d65abf + bffb760 commit d17b7f6

22 files changed

+91
-93
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ lint_single_use_lifetime = lifetime parameter `{$ident}` only used once
761761
762762
lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
763763
764-
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static is discouraged
764+
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static
765765
.label = {$shared_label}reference to mutable static
766766
.suggestion = use `&raw const` instead to create a raw pointer
767767
.suggestion_mut = use `&raw mut` instead to create a raw pointer

compiler/rustc_lint/src/static_mut_refs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare_lint! {
5151
/// This lint is "warn" by default on editions up to 2021, in 2024 is "deny".
5252
pub STATIC_MUT_REFS,
5353
Warn,
54-
"shared references or mutable references of mutable static is discouraged",
54+
"creating a shared reference to mutable static",
5555
@future_incompatible = FutureIncompatibleInfo {
5656
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
5757
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>",

src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ LL | if result.is_ok() {
236236
LL | result.as_mut().unwrap();
237237
| ^^^^^^^^^^^^^^^^^^^^^^^^
238238

239-
error: creating a shared reference to mutable static is discouraged
239+
error: creating a shared reference to mutable static
240240
--> tests/ui/checked_unwrap/simple_conditionals.rs:183:12
241241
|
242242
LL | if X.is_some() {

tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Foo {
1717
fn main() {
1818
unsafe {
1919
let sfoo: *mut Foo = &mut SFOO;
20-
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
20+
//~^ WARN mutable reference to mutable static [static_mut_refs]
2121
let x = (*sfoo).x();
2222
(*sfoo).x[1] += 1;
2323
*x += 1;

tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: creating a mutable reference to mutable static is discouraged
1+
warning: creating a mutable reference to mutable static
22
--> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30
33
|
44
LL | let sfoo: *mut Foo = &mut SFOO;

tests/ui/consts/const_let_assign2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static mut BB: AA = AA::new();
1616

1717
fn main() {
1818
let ptr = unsafe { &mut BB };
19-
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
19+
//~^ WARN mutable reference to mutable static [static_mut_refs]
2020
for a in ptr.data.iter() {
2121
println!("{}", a);
2222
}

tests/ui/consts/const_let_assign2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: creating a mutable reference to mutable static is discouraged
1+
warning: creating a mutable reference to mutable static
22
--> $DIR/const_let_assign2.rs:18:24
33
|
44
LL | let ptr = unsafe { &mut BB };

tests/ui/issues/issue-39367.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn arena() -> &'static ArenaSet<Vec<u8>> {
2020

2121
static mut ONCE: Once = Once::new();
2222
ONCE.call_once(|| {
23-
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
23+
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
2424
DATA = transmute
2525
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
2626
(Box::new(__static_ref_initialize()));

tests/ui/issues/issue-39367.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: creating a shared reference to mutable static is discouraged
1+
warning: creating a shared reference to mutable static
22
--> $DIR/issue-39367.rs:22:13
33
|
44
LL | / ONCE.call_once(|| {

tests/ui/lint/static-mut-refs.e2021.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: creating a shared reference to mutable static is discouraged
1+
warning: creating a shared reference to mutable static
22
--> $DIR/static-mut-refs.rs:38:18
33
|
44
LL | let _y = &X;
@@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
1212
LL | let _y = &raw const X;
1313
| +++++++++
1414

15-
warning: creating a mutable reference to mutable static is discouraged
15+
warning: creating a mutable reference to mutable static
1616
--> $DIR/static-mut-refs.rs:42:18
1717
|
1818
LL | let _y = &mut X;
@@ -25,7 +25,7 @@ help: use `&raw mut` instead to create a raw pointer
2525
LL | let _y = &raw mut X;
2626
| +++
2727

28-
warning: creating a shared reference to mutable static is discouraged
28+
warning: creating a shared reference to mutable static
2929
--> $DIR/static-mut-refs.rs:50:22
3030
|
3131
LL | let ref _a = X;
@@ -34,7 +34,7 @@ LL | let ref _a = X;
3434
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
3535
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
3636

37-
warning: creating a shared reference to mutable static is discouraged
37+
warning: creating a shared reference to mutable static
3838
--> $DIR/static-mut-refs.rs:54:25
3939
|
4040
LL | let (_b, _c) = (&X, &Y);
@@ -47,7 +47,7 @@ help: use `&raw const` instead to create a raw pointer
4747
LL | let (_b, _c) = (&raw const X, &Y);
4848
| +++++++++
4949

50-
warning: creating a shared reference to mutable static is discouraged
50+
warning: creating a shared reference to mutable static
5151
--> $DIR/static-mut-refs.rs:54:29
5252
|
5353
LL | let (_b, _c) = (&X, &Y);
@@ -60,7 +60,7 @@ help: use `&raw const` instead to create a raw pointer
6060
LL | let (_b, _c) = (&X, &raw const Y);
6161
| +++++++++
6262

63-
warning: creating a shared reference to mutable static is discouraged
63+
warning: creating a shared reference to mutable static
6464
--> $DIR/static-mut-refs.rs:60:13
6565
|
6666
LL | foo(&X);
@@ -73,7 +73,7 @@ help: use `&raw const` instead to create a raw pointer
7373
LL | foo(&raw const X);
7474
| +++++++++
7575

76-
warning: creating a shared reference to mutable static is discouraged
76+
warning: creating a shared reference to mutable static
7777
--> $DIR/static-mut-refs.rs:66:17
7878
|
7979
LL | let _ = Z.len();
@@ -82,7 +82,7 @@ LL | let _ = Z.len();
8282
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
8383
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
8484

85-
warning: creating a shared reference to mutable static is discouraged
85+
warning: creating a shared reference to mutable static
8686
--> $DIR/static-mut-refs.rs:72:33
8787
|
8888
LL | let _ = format!("{:?}", Z);
@@ -91,7 +91,7 @@ LL | let _ = format!("{:?}", Z);
9191
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
9292
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
9393

94-
warning: creating a shared reference to mutable static is discouraged
94+
warning: creating a shared reference to mutable static
9595
--> $DIR/static-mut-refs.rs:76:18
9696
|
9797
LL | let _v = &A.value;
@@ -104,7 +104,7 @@ help: use `&raw const` instead to create a raw pointer
104104
LL | let _v = &raw const A.value;
105105
| +++++++++
106106

107-
warning: creating a shared reference to mutable static is discouraged
107+
warning: creating a shared reference to mutable static
108108
--> $DIR/static-mut-refs.rs:80:18
109109
|
110110
LL | let _s = &A.s.value;
@@ -117,7 +117,7 @@ help: use `&raw const` instead to create a raw pointer
117117
LL | let _s = &raw const A.s.value;
118118
| +++++++++
119119

120-
warning: creating a shared reference to mutable static is discouraged
120+
warning: creating a shared reference to mutable static
121121
--> $DIR/static-mut-refs.rs:84:22
122122
|
123123
LL | let ref _v = A.value;
@@ -126,7 +126,7 @@ LL | let ref _v = A.value;
126126
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
127127
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
128128

129-
warning: creating a mutable reference to mutable static is discouraged
129+
warning: creating a mutable reference to mutable static
130130
--> $DIR/static-mut-refs.rs:14:14
131131
|
132132
LL | &mut ($x.0)

tests/ui/lint/static-mut-refs.e2024.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: creating a shared reference to mutable static is discouraged
1+
error: creating a shared reference to mutable static
22
--> $DIR/static-mut-refs.rs:38:18
33
|
44
LL | let _y = &X;
@@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
1212
LL | let _y = &raw const X;
1313
| +++++++++
1414

15-
error: creating a mutable reference to mutable static is discouraged
15+
error: creating a mutable reference to mutable static
1616
--> $DIR/static-mut-refs.rs:42:18
1717
|
1818
LL | let _y = &mut X;
@@ -25,7 +25,7 @@ help: use `&raw mut` instead to create a raw pointer
2525
LL | let _y = &raw mut X;
2626
| +++
2727

28-
error: creating a shared reference to mutable static is discouraged
28+
error: creating a shared reference to mutable static
2929
--> $DIR/static-mut-refs.rs:50:22
3030
|
3131
LL | let ref _a = X;
@@ -34,7 +34,7 @@ LL | let ref _a = X;
3434
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
3535
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
3636

37-
error: creating a shared reference to mutable static is discouraged
37+
error: creating a shared reference to mutable static
3838
--> $DIR/static-mut-refs.rs:54:25
3939
|
4040
LL | let (_b, _c) = (&X, &Y);
@@ -47,7 +47,7 @@ help: use `&raw const` instead to create a raw pointer
4747
LL | let (_b, _c) = (&raw const X, &Y);
4848
| +++++++++
4949

50-
error: creating a shared reference to mutable static is discouraged
50+
error: creating a shared reference to mutable static
5151
--> $DIR/static-mut-refs.rs:54:29
5252
|
5353
LL | let (_b, _c) = (&X, &Y);
@@ -60,7 +60,7 @@ help: use `&raw const` instead to create a raw pointer
6060
LL | let (_b, _c) = (&X, &raw const Y);
6161
| +++++++++
6262

63-
error: creating a shared reference to mutable static is discouraged
63+
error: creating a shared reference to mutable static
6464
--> $DIR/static-mut-refs.rs:60:13
6565
|
6666
LL | foo(&X);
@@ -73,7 +73,7 @@ help: use `&raw const` instead to create a raw pointer
7373
LL | foo(&raw const X);
7474
| +++++++++
7575

76-
error: creating a shared reference to mutable static is discouraged
76+
error: creating a shared reference to mutable static
7777
--> $DIR/static-mut-refs.rs:66:17
7878
|
7979
LL | let _ = Z.len();
@@ -82,7 +82,7 @@ LL | let _ = Z.len();
8282
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
8383
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
8484

85-
error: creating a shared reference to mutable static is discouraged
85+
error: creating a shared reference to mutable static
8686
--> $DIR/static-mut-refs.rs:72:33
8787
|
8888
LL | let _ = format!("{:?}", Z);
@@ -91,7 +91,7 @@ LL | let _ = format!("{:?}", Z);
9191
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
9292
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
9393

94-
error: creating a shared reference to mutable static is discouraged
94+
error: creating a shared reference to mutable static
9595
--> $DIR/static-mut-refs.rs:76:18
9696
|
9797
LL | let _v = &A.value;
@@ -104,7 +104,7 @@ help: use `&raw const` instead to create a raw pointer
104104
LL | let _v = &raw const A.value;
105105
| +++++++++
106106

107-
error: creating a shared reference to mutable static is discouraged
107+
error: creating a shared reference to mutable static
108108
--> $DIR/static-mut-refs.rs:80:18
109109
|
110110
LL | let _s = &A.s.value;
@@ -117,7 +117,7 @@ help: use `&raw const` instead to create a raw pointer
117117
LL | let _s = &raw const A.s.value;
118118
| +++++++++
119119

120-
error: creating a shared reference to mutable static is discouraged
120+
error: creating a shared reference to mutable static
121121
--> $DIR/static-mut-refs.rs:84:22
122122
|
123123
LL | let ref _v = A.value;
@@ -126,7 +126,7 @@ LL | let ref _v = A.value;
126126
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
127127
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
128128

129-
error: creating a mutable reference to mutable static is discouraged
129+
error: creating a mutable reference to mutable static
130130
--> $DIR/static-mut-refs.rs:14:14
131131
|
132132
LL | &mut ($x.0)

tests/ui/lint/static-mut-refs.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ static mut FOO: (u32, u32) = (1, 2);
1212
macro_rules! bar {
1313
($x:expr) => {
1414
&mut ($x.0)
15-
//[e2021]~^ WARN creating a mutable reference to mutable static is discouraged [static_mut_refs]
16-
//[e2024]~^^ ERROR creating a mutable reference to mutable static is discouraged [static_mut_refs]
15+
//[e2021]~^ WARN creating a mutable reference to mutable static [static_mut_refs]
16+
//[e2024]~^^ ERROR creating a mutable reference to mutable static [static_mut_refs]
1717
};
1818
}
1919

@@ -36,54 +36,54 @@ fn main() {
3636

3737
unsafe {
3838
let _y = &X;
39-
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
40-
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
39+
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
40+
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
4141

4242
let _y = &mut X;
43-
//[e2021]~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
44-
//[e2024]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs]
43+
//[e2021]~^ WARN mutable reference to mutable static [static_mut_refs]
44+
//[e2024]~^^ ERROR mutable reference to mutable static [static_mut_refs]
4545

4646
let _z = &raw mut X;
4747

4848
let _p = &raw const X;
4949

5050
let ref _a = X;
51-
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
52-
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
51+
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
52+
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
5353

5454
let (_b, _c) = (&X, &Y);
55-
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
56-
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
57-
//[e2021]~^^^ WARN shared reference to mutable static is discouraged [static_mut_refs]
58-
//[e2024]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
55+
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
56+
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
57+
//[e2021]~^^^ WARN shared reference to mutable static [static_mut_refs]
58+
//[e2024]~^^^^ ERROR shared reference to mutable static [static_mut_refs]
5959

6060
foo(&X);
61-
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
62-
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
61+
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
62+
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
6363

6464
static mut Z: &[i32; 3] = &[0, 1, 2];
6565

6666
let _ = Z.len();
67-
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
68-
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
67+
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
68+
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
6969

7070
let _ = Z[0];
7171

7272
let _ = format!("{:?}", Z);
73-
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
74-
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
73+
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
74+
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
7575

7676
let _v = &A.value;
77-
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
78-
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
77+
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
78+
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
7979

8080
let _s = &A.s.value;
81-
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
82-
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
81+
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
82+
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
8383

8484
let ref _v = A.value;
85-
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
86-
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
85+
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
86+
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
8787

8888
let _x = bar!(FOO);
8989

tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct S1 {
1515
impl S1 {
1616
fn new(_x: u64) -> S1 {
1717
S1 { a: unsafe { &mut X1 } }
18-
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
18+
//~^ WARN mutable reference to mutable static [static_mut_refs]
1919
}
2020
}
2121

tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: creating a mutable reference to mutable static is discouraged
1+
warning: creating a mutable reference to mutable static
22
--> $DIR/borrowck-thread-local-static-mut-borrow-outlives-fn.rs:17:26
33
|
44
LL | S1 { a: unsafe { &mut X1 } }

tests/ui/statics/issue-15261.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#![allow(dead_code)]
33
#![allow(non_upper_case_globals)]
44

5-
65
static mut n_mut: usize = 0;
76

87
static n: &'static usize = unsafe { &n_mut };
9-
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
8+
//~^ WARN shared reference to mutable static [static_mut_refs]
109

1110
fn main() {}

0 commit comments

Comments
 (0)