@@ -37,56 +37,68 @@ LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
3737 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838
3939error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
40- --> $DIR/reference_casting.rs:29:16
40+ --> $DIR/reference_casting.rs:27:16
41+ |
42+ LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
43+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
46+ --> $DIR/reference_casting.rs:31:16
4147 |
4248LL | let deferred = num as *const i32 as *mut i32;
4349 | ----------------------------- casting happend here
4450LL | let _num = &mut *deferred;
4551 | ^^^^^^^^^^^^^^
4652
4753error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
48- --> $DIR/reference_casting.rs:38 :5
54+ --> $DIR/reference_casting.rs:40 :5
4955 |
5056LL | *(a as *const _ as *mut _) = String::from("Replaced");
5157 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5258
5359error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
54- --> $DIR/reference_casting.rs:40 :5
60+ --> $DIR/reference_casting.rs:42 :5
5561 |
5662LL | *(a as *const _ as *mut String) += " world";
5763 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5864
5965error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
60- --> $DIR/reference_casting.rs:42 :5
66+ --> $DIR/reference_casting.rs:44 :5
6167 |
6268LL | *std::ptr::from_ref(num).cast_mut() += 1;
6369 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6470
6571error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
66- --> $DIR/reference_casting.rs:44 :5
72+ --> $DIR/reference_casting.rs:46 :5
6773 |
6874LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
6975 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7076
7177error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
72- --> $DIR/reference_casting.rs:46 :5
78+ --> $DIR/reference_casting.rs:48 :5
7379 |
7480LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
7581 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7682
7783error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
78- --> $DIR/reference_casting.rs:48 :5
84+ --> $DIR/reference_casting.rs:50 :5
7985 |
8086LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
8187 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8288
8389error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
84- --> $DIR/reference_casting.rs:51:5
90+ --> $DIR/reference_casting.rs:52:5
91+ |
92+ LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
93+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
95+ error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
96+ --> $DIR/reference_casting.rs:56:5
8597 |
8698LL | let value = num as *const i32 as *mut i32;
8799 | ----------------------------- casting happend here
88100LL | *value = 1;
89101 | ^^^^^^^^^^
90102
91- error: aborting due to 14 previous errors
103+ error: aborting due to 16 previous errors
92104
0 commit comments