summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/reference_casting.stderr
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/lint/reference_casting.stderr')
-rw-r--r--tests/ui/lint/reference_casting.stderr162
1 files changed, 127 insertions, 35 deletions
diff --git a/tests/ui/lint/reference_casting.stderr b/tests/ui/lint/reference_casting.stderr
index d5b9bbef6..7ff9b76a8 100644
--- a/tests/ui/lint/reference_casting.stderr
+++ b/tests/ui/lint/reference_casting.stderr
@@ -1,68 +1,160 @@
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:20:9
+ --> $DIR/reference_casting.rs:19:16
|
-LL | (*(a as *const _ as *mut String)).push_str(" world");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(num as *const i32 as *mut i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[deny(invalid_reference_casting)]` on by default
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:21:16
+ |
+LL | let _num = &mut *(num as *const i32).cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:23:16
+ |
+LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:25:16
|
-note: the lint level is defined here
- --> $DIR/reference_casting.rs:4:9
+LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:27:16
|
-LL | #![deny(invalid_reference_casting)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:22:9
+ --> $DIR/reference_casting.rs:29:16
|
-LL | *(a as *const _ as *mut _) = String::from("Replaced");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:24:9
+ --> $DIR/reference_casting.rs:31:16
|
-LL | *(a as *const _ as *mut String) += " world";
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:26:25
+ --> $DIR/reference_casting.rs:33:16
|
-LL | let _num = &mut *(num as *const i32 as *mut i32);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:28:25
+ --> $DIR/reference_casting.rs:35:16
|
-LL | let _num = &mut *(num as *const i32).cast_mut();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:30:20
+ --> $DIR/reference_casting.rs:37:16
|
-LL | let _num = *{ num as *const i32 }.cast_mut();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:32:9
+ --> $DIR/reference_casting.rs:41:16
|
-LL | *std::ptr::from_ref(num).cast_mut() += 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let deferred = num as *const i32 as *mut i32;
+ | ----------------------------- casting happend here
+LL | let _num = &mut *deferred;
+ | ^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:34:9
+ --> $DIR/reference_casting.rs:44:16
|
-LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
+ | ---------------------------------------------------------------------------- casting happend here
+LL | let _num = &mut *deferred;
+ | ^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:36:9
+ --> $DIR/reference_casting.rs:46:16
|
-LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _num = &mut *(num as *const _ as usize as *mut i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
- --> $DIR/reference_casting.rs:38:9
+ --> $DIR/reference_casting.rs:50:9
+ |
+LL | &mut *((this as *const _) as *mut _)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:60:5
+ |
+LL | *(a as *const _ as *mut _) = String::from("Replaced");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:62:5
+ |
+LL | *(a as *const _ as *mut String) += " world";
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:64:5
|
-LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | *std::ptr::from_ref(num).cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:66:5
+ |
+LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:68:5
+ |
+LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:70:5
+ |
+LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:72:5
+ |
+LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:76:5
+ |
+LL | let value = num as *const i32 as *mut i32;
+ | ----------------------------- casting happend here
+LL | *value = 1;
+ | ^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:78:5
+ |
+LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:80:5
+ |
+LL | *(num as *const _ as usize as *mut i32) = 2;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:84:9
+ |
+LL | *(this as *const _ as *mut _) = a;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 10 previous errors
+error: aborting due to 25 previous errors