about summary refs log tree commit diff
path: root/tests/ui/statics
diff options
context:
space:
mode:
authoryuk1ty <yuk1ty@users.noreply.github.com>2025-04-20 10:51:19 +0900
committeryuk1ty <yuk1ty@users.noreply.github.com>2025-04-26 14:48:30 +0900
commitbffb7608ce727d61cb1d9d3bb58d5461375f59a5 (patch)
treed4494c7a87053feae77833ec16f8f520782ee693 /tests/ui/statics
parentd3508a8ad0163fab0c9b2188b3adf43c87200788 (diff)
downloadrust-bffb7608ce727d61cb1d9d3bb58d5461375f59a5.tar.gz
rust-bffb7608ce727d61cb1d9d3bb58d5461375f59a5.zip
Fix error message for static references or mutable references
Diffstat (limited to 'tests/ui/statics')
-rw-r--r--tests/ui/statics/issue-15261.rs3
-rw-r--r--tests/ui/statics/issue-15261.stderr4
-rw-r--r--tests/ui/statics/static-mut-shared-parens.rs7
-rw-r--r--tests/ui/statics/static-mut-shared-parens.stderr16
-rw-r--r--tests/ui/statics/static-mut-xc.rs14
-rw-r--r--tests/ui/statics/static-mut-xc.stderr14
-rw-r--r--tests/ui/statics/static-recursive.rs4
-rw-r--r--tests/ui/statics/static-recursive.stderr4
8 files changed, 32 insertions, 34 deletions
diff --git a/tests/ui/statics/issue-15261.rs b/tests/ui/statics/issue-15261.rs
index ed79a201488..f8c5ebaa548 100644
--- a/tests/ui/statics/issue-15261.rs
+++ b/tests/ui/statics/issue-15261.rs
@@ -2,10 +2,9 @@
 #![allow(dead_code)]
 #![allow(non_upper_case_globals)]
 
-
 static mut n_mut: usize = 0;
 
 static n: &'static usize = unsafe { &n_mut };
-//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
+//~^ WARN shared reference to mutable static [static_mut_refs]
 
 fn main() {}
diff --git a/tests/ui/statics/issue-15261.stderr b/tests/ui/statics/issue-15261.stderr
index 7e6aebcbb1f..d2dd762aa66 100644
--- a/tests/ui/statics/issue-15261.stderr
+++ b/tests/ui/statics/issue-15261.stderr
@@ -1,5 +1,5 @@
-warning: creating a shared reference to mutable static is discouraged
-  --> $DIR/issue-15261.rs:8:37
+warning: creating a shared reference to mutable static
+  --> $DIR/issue-15261.rs:7:37
    |
 LL | static n: &'static usize = unsafe { &n_mut };
    |                                     ^^^^^^ shared reference to mutable static
diff --git a/tests/ui/statics/static-mut-shared-parens.rs b/tests/ui/statics/static-mut-shared-parens.rs
index 8e58152e27a..7eda7d67d92 100644
--- a/tests/ui/statics/static-mut-shared-parens.rs
+++ b/tests/ui/statics/static-mut-shared-parens.rs
@@ -1,13 +1,12 @@
 //Missing paren in diagnostic msg: https://github.com/rust-lang/rust/issues/131977
 //@check-pass
 
-
 static mut TEST: usize = 0;
 
 fn main() {
     let _ = unsafe { (&TEST) as *const usize };
-    //~^WARN creating a shared reference to mutable static is discouraged
+    //~^WARN creating a shared reference to mutable static
 
-    let _ = unsafe { ((&mut TEST)) as *const usize };
-    //~^WARN creating a mutable reference to mutable static is discouraged
+    let _ = unsafe { (&mut TEST) as *const usize };
+    //~^WARN creating a mutable reference to mutable static
 }
diff --git a/tests/ui/statics/static-mut-shared-parens.stderr b/tests/ui/statics/static-mut-shared-parens.stderr
index 30a586c286a..3825e8efc42 100644
--- a/tests/ui/statics/static-mut-shared-parens.stderr
+++ b/tests/ui/statics/static-mut-shared-parens.stderr
@@ -1,5 +1,5 @@
-warning: creating a shared reference to mutable static is discouraged
-  --> $DIR/static-mut-shared-parens.rs:8:22
+warning: creating a shared reference to mutable static
+  --> $DIR/static-mut-shared-parens.rs:7:22
    |
 LL |     let _ = unsafe { (&TEST) as *const usize };
    |                      ^^^^^^^ shared reference to mutable static
@@ -12,18 +12,18 @@ help: use `&raw const` instead to create a raw pointer
 LL |     let _ = unsafe { (&raw const TEST) as *const usize };
    |                        +++++++++
 
-warning: creating a mutable reference to mutable static is discouraged
-  --> $DIR/static-mut-shared-parens.rs:11:22
+warning: creating a mutable reference to mutable static
+  --> $DIR/static-mut-shared-parens.rs:10:22
    |
-LL |     let _ = unsafe { ((&mut TEST)) as *const usize };
-   |                      ^^^^^^^^^^^^^ mutable reference to mutable static
+LL |     let _ = unsafe { (&mut TEST) as *const usize };
+   |                      ^^^^^^^^^^^ mutable reference to mutable static
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives
 help: use `&raw mut` instead to create a raw pointer
    |
-LL |     let _ = unsafe { ((&raw mut TEST)) as *const usize };
-   |                         +++
+LL |     let _ = unsafe { (&raw mut TEST) as *const usize };
+   |                        +++
 
 warning: 2 warnings emitted
 
diff --git a/tests/ui/statics/static-mut-xc.rs b/tests/ui/statics/static-mut-xc.rs
index c23cc822ce7..878f5a8e0f7 100644
--- a/tests/ui/statics/static-mut-xc.rs
+++ b/tests/ui/statics/static-mut-xc.rs
@@ -17,23 +17,23 @@ fn static_bound_set(a: &'static mut isize) {
 
 unsafe fn run() {
     assert_eq!(static_mut_xc::a, 3);
-    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     static_mut_xc::a = 4;
     assert_eq!(static_mut_xc::a, 4);
-    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     static_mut_xc::a += 1;
     assert_eq!(static_mut_xc::a, 5);
-    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     static_mut_xc::a *= 3;
     assert_eq!(static_mut_xc::a, 15);
-    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     static_mut_xc::a = -3;
     assert_eq!(static_mut_xc::a, -3);
-    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     static_bound(&static_mut_xc::a);
-    //~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN shared reference to mutable static [static_mut_refs]
     static_bound_set(&mut static_mut_xc::a);
-    //~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
+    //~^ WARN mutable reference to mutable static [static_mut_refs]
 }
 
 pub fn main() {
diff --git a/tests/ui/statics/static-mut-xc.stderr b/tests/ui/statics/static-mut-xc.stderr
index 69f334a5636..2d7a0553e92 100644
--- a/tests/ui/statics/static-mut-xc.stderr
+++ b/tests/ui/statics/static-mut-xc.stderr
@@ -1,4 +1,4 @@
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:19:16
    |
 LL |     assert_eq!(static_mut_xc::a, 3);
@@ -8,7 +8,7 @@ LL |     assert_eq!(static_mut_xc::a, 3);
    = 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
    = note: `#[warn(static_mut_refs)]` on by default
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:22:16
    |
 LL |     assert_eq!(static_mut_xc::a, 4);
@@ -17,7 +17,7 @@ LL |     assert_eq!(static_mut_xc::a, 4);
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = 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
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:25:16
    |
 LL |     assert_eq!(static_mut_xc::a, 5);
@@ -26,7 +26,7 @@ LL |     assert_eq!(static_mut_xc::a, 5);
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = 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
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:28:16
    |
 LL |     assert_eq!(static_mut_xc::a, 15);
@@ -35,7 +35,7 @@ LL |     assert_eq!(static_mut_xc::a, 15);
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = 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
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:31:16
    |
 LL |     assert_eq!(static_mut_xc::a, -3);
@@ -44,7 +44,7 @@ LL |     assert_eq!(static_mut_xc::a, -3);
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = 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
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-mut-xc.rs:33:18
    |
 LL |     static_bound(&static_mut_xc::a);
@@ -57,7 +57,7 @@ help: use `&raw const` instead to create a raw pointer
 LL |     static_bound(&raw const static_mut_xc::a);
    |                   +++++++++
 
-warning: creating a mutable reference to mutable static is discouraged
+warning: creating a mutable reference to mutable static
   --> $DIR/static-mut-xc.rs:35:22
    |
 LL |     static_bound_set(&mut static_mut_xc::a);
diff --git a/tests/ui/statics/static-recursive.rs b/tests/ui/statics/static-recursive.rs
index da23b54d1fc..dab60dd8641 100644
--- a/tests/ui/statics/static-recursive.rs
+++ b/tests/ui/statics/static-recursive.rs
@@ -1,7 +1,7 @@
 //@ run-pass
 
 static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
-//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
+//~^ WARN shared reference to mutable static [static_mut_refs]
 
 struct StaticDoubleLinked {
     prev: &'static StaticDoubleLinked,
@@ -17,7 +17,7 @@ static L3: StaticDoubleLinked = StaticDoubleLinked { prev: &L2, next: &L1, data:
 pub fn main() {
     unsafe {
         assert_eq!(S, *(S as *const *const u8));
-        //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
+        //~^ WARN creating a shared reference to mutable static [static_mut_refs]
     }
 
     let mut test_vec = Vec::new();
diff --git a/tests/ui/statics/static-recursive.stderr b/tests/ui/statics/static-recursive.stderr
index 039934dfc69..252807e2e5d 100644
--- a/tests/ui/statics/static-recursive.stderr
+++ b/tests/ui/statics/static-recursive.stderr
@@ -1,4 +1,4 @@
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-recursive.rs:3:36
    |
 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
 LL | static mut S: *const u8 = unsafe { &raw const S as *const *const u8 as *const u8 };
    |                                     +++++++++
 
-warning: creating a shared reference to mutable static is discouraged
+warning: creating a shared reference to mutable static
   --> $DIR/static-recursive.rs:19:20
    |
 LL |         assert_eq!(S, *(S as *const *const u8));