Skip to content

Commit a8ec2f7

Browse files
committed
Fix error message for static references or mutable references
1 parent 2ef7858 commit a8ec2f7

12 files changed

+42
-42
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ lint_single_use_lifetime = lifetime parameter `{$ident}` only used once
757757
758758
lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
759759
760-
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static is discouraged
760+
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static is not allowed
761761
.label = {$shared_label}reference to mutable static
762762
.suggestion = use `&raw const` instead to create a raw pointer
763763
.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+
"shared references or mutable references of mutable static is not allowed",
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>",

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 is not allowed
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.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 is not allowed
22
--> $DIR/const_let_assign2.rs:18:24
33
|
44
LL | let ptr = unsafe { &mut BB };

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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
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 is not allowed
130130
--> $DIR/static-mut-refs.rs:14:14
131131
|
132132
LL | &mut ($x.0)

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 is not allowed
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.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 is not allowed
22
--> $DIR/issue-15261.rs:8:37
33
|
44
LL | static n: &'static usize = unsafe { &n_mut };

tests/ui/statics/static-mut-shared-parens.stderr

+2-2
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 is not allowed
22
--> $DIR/static-mut-shared-parens.rs:8:22
33
|
44
LL | let _ = unsafe { (&TEST) as *const usize };
@@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
1212
LL | let _ = unsafe { (&raw const TEST) as *const usize };
1313
| +++++++++
1414

15-
warning: creating a mutable reference to mutable static is discouraged
15+
warning: creating a mutable reference to mutable static is not allowed
1616
--> $DIR/static-mut-shared-parens.rs:11:22
1717
|
1818
LL | let _ = unsafe { ((&mut TEST)) as *const usize };

tests/ui/statics/static-mut-xc.stderr

+7-7
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 is not allowed
22
--> $DIR/static-mut-xc.rs:19:16
33
|
44
LL | assert_eq!(static_mut_xc::a, 3);
@@ -8,7 +8,7 @@ LL | assert_eq!(static_mut_xc::a, 3);
88
= 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
99
= note: `#[warn(static_mut_refs)]` on by default
1010

11-
warning: creating a shared reference to mutable static is discouraged
11+
warning: creating a shared reference to mutable static is not allowed
1212
--> $DIR/static-mut-xc.rs:22:16
1313
|
1414
LL | assert_eq!(static_mut_xc::a, 4);
@@ -17,7 +17,7 @@ LL | assert_eq!(static_mut_xc::a, 4);
1717
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
1818
= 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
1919

20-
warning: creating a shared reference to mutable static is discouraged
20+
warning: creating a shared reference to mutable static is not allowed
2121
--> $DIR/static-mut-xc.rs:25:16
2222
|
2323
LL | assert_eq!(static_mut_xc::a, 5);
@@ -26,7 +26,7 @@ LL | assert_eq!(static_mut_xc::a, 5);
2626
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
2727
= 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
2828

29-
warning: creating a shared reference to mutable static is discouraged
29+
warning: creating a shared reference to mutable static is not allowed
3030
--> $DIR/static-mut-xc.rs:28:16
3131
|
3232
LL | assert_eq!(static_mut_xc::a, 15);
@@ -35,7 +35,7 @@ LL | assert_eq!(static_mut_xc::a, 15);
3535
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
3636
= 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
3737

38-
warning: creating a shared reference to mutable static is discouraged
38+
warning: creating a shared reference to mutable static is not allowed
3939
--> $DIR/static-mut-xc.rs:31:16
4040
|
4141
LL | assert_eq!(static_mut_xc::a, -3);
@@ -44,7 +44,7 @@ LL | assert_eq!(static_mut_xc::a, -3);
4444
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
4545
= 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
4646

47-
warning: creating a shared reference to mutable static is discouraged
47+
warning: creating a shared reference to mutable static is not allowed
4848
--> $DIR/static-mut-xc.rs:33:18
4949
|
5050
LL | static_bound(&static_mut_xc::a);
@@ -57,7 +57,7 @@ help: use `&raw const` instead to create a raw pointer
5757
LL | static_bound(&raw const static_mut_xc::a);
5858
| +++++++++
5959

60-
warning: creating a mutable reference to mutable static is discouraged
60+
warning: creating a mutable reference to mutable static is not allowed
6161
--> $DIR/static-mut-xc.rs:35:22
6262
|
6363
LL | static_bound_set(&mut static_mut_xc::a);

tests/ui/statics/static-recursive.stderr

+2-2
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 is not allowed
22
--> $DIR/static-recursive.rs:3:36
33
|
44
LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
@@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
1212
LL | static mut S: *const u8 = unsafe { &raw const S as *const *const u8 as *const u8 };
1313
| +++++++++
1414

15-
warning: creating a shared reference to mutable static is discouraged
15+
warning: creating a shared reference to mutable static is not allowed
1616
--> $DIR/static-recursive.rs:19:20
1717
|
1818
LL | assert_eq!(S, *(S as *const *const u8));

0 commit comments

Comments
 (0)