about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lint/reference_casting.rs3
-rw-r--r--tests/ui/lint/reference_casting.stderr10
2 files changed, 12 insertions, 1 deletions
diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs
index 745d7070143..c3168cd4c01 100644
--- a/tests/ui/lint/reference_casting.rs
+++ b/tests/ui/lint/reference_casting.rs
@@ -36,6 +36,9 @@ fn main() {
         //~^ ERROR casting `&T` to `&mut T` is undefined behavior
         *(std::ptr::from_ref({ num }) as *mut i32) += 1;
         //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+        let value = num as *const i32 as *mut i32;
+        *value = 1;
+        //~^ ERROR casting `&T` to `&mut T` is undefined behavior
 
         // Shouldn't be warned against
         println!("{}", *(num as *const _ as *const i16));
diff --git a/tests/ui/lint/reference_casting.stderr b/tests/ui/lint/reference_casting.stderr
index d1dd1b32ff4..d9ce4b38387 100644
--- a/tests/ui/lint/reference_casting.stderr
+++ b/tests/ui/lint/reference_casting.stderr
@@ -60,5 +60,13 @@ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is
 LL |         *(std::ptr::from_ref({ num }) as *mut i32) += 1;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 10 previous errors
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+  --> $DIR/reference_casting.rs:40:9
+   |
+LL |         let value = num as *const i32 as *mut i32;
+   |                     ----------------------------- casting happend here
+LL |         *value = 1;
+   |         ^^^^^^
+
+error: aborting due to 11 previous errors