mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
61 lines
2.7 KiB
Plaintext
61 lines
2.7 KiB
Plaintext
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
|
--> $DIR/reference_casting.rs:19:9
|
|
|
|
|
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= 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:9
|
|
|
|
|
LL | *(a as *const _ as *mut String) += " world";
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
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:20
|
|
|
|
|
LL | let _num = &mut *(num as *const i32 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:25:20
|
|
|
|
|
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:27:9
|
|
|
|
|
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
|
--> $DIR/reference_casting.rs:29:9
|
|
|
|
|
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
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:9
|
|
|
|
|
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
|
--> $DIR/reference_casting.rs:33:9
|
|
|
|
|
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
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
|
|
|
|
|
LL | let value = num as *const i32 as *mut i32;
|
|
| ----------------------------- casting happend here
|
|
LL | *value = 1;
|
|
| ^^^^^^^^^^
|
|
|
|
error: aborting due to 9 previous errors
|
|
|