2023-05-14 09:20:32 -05:00
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:15:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *(num as *const i32 as *mut i32);
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 14:54:27 -05:00
|
|
|
= note: `#[deny(invalid_reference_casting)]` on by default
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:17:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *(num as *const i32).cast_mut();
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:19:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:21:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:23:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-07-14 15:25:47 -05:00
|
|
|
--> $DIR/reference_casting.rs:25:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:27:16
|
|
|
|
|
|
|
|
|
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:31:16
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let deferred = num as *const i32 as *mut i32;
|
|
|
|
| ----------------------------- casting happend here
|
|
|
|
LL | let _num = &mut *deferred;
|
|
|
|
| ^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:40:5
|
2023-05-14 09:20:32 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2023-05-14 09:20:32 -05:00
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:42:5
|
2023-07-14 15:25:47 -05:00
|
|
|
|
|
|
|
|
LL | *(a as *const _ as *mut String) += " world";
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:44:5
|
2023-07-14 15:25:47 -05:00
|
|
|
|
|
|
|
|
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:46:5
|
2023-07-14 15:25:47 -05:00
|
|
|
|
|
|
|
|
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:48:5
|
2023-07-14 15:25:47 -05:00
|
|
|
|
|
|
|
|
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:50:5
|
2023-07-14 15:25:47 -05:00
|
|
|
|
|
|
|
|
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
2023-08-12 05:40:26 -05:00
|
|
|
--> $DIR/reference_casting.rs:52:5
|
|
|
|
|
|
|
|
|
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
|
|
|
--> $DIR/reference_casting.rs:56:5
|
2023-07-14 15:10:14 -05:00
|
|
|
|
|
2023-07-14 15:25:47 -05:00
|
|
|
LL | let value = num as *const i32 as *mut i32;
|
|
|
|
| ----------------------------- casting happend here
|
|
|
|
LL | *value = 1;
|
|
|
|
| ^^^^^^^^^^
|
2023-07-14 15:10:14 -05:00
|
|
|
|
2023-08-12 05:40:26 -05:00
|
|
|
error: aborting due to 16 previous errors
|
2023-05-14 09:20:32 -05:00
|
|
|
|