|
1 | 1 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
2 |
| - --> $DIR/reference_casting.rs:19:9 |
| 2 | + --> $DIR/reference_casting.rs:15:16 |
3 | 3 | |
|
4 |
| -LL | *(a as *const _ as *mut _) = String::from("Replaced"); |
5 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 4 | +LL | let _num = &mut *(num as *const i32 as *mut i32); |
| 5 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
6 | 6 | |
|
7 | 7 | = note: `#[deny(invalid_reference_casting)]` on by default
|
8 | 8 |
|
9 | 9 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
10 |
| - --> $DIR/reference_casting.rs:21:9 |
| 10 | + --> $DIR/reference_casting.rs:17:16 |
11 | 11 | |
|
12 |
| -LL | *(a as *const _ as *mut String) += " world"; |
13 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 12 | +LL | let _num = &mut *(num as *const i32).cast_mut(); |
| 13 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
14 | 14 |
|
15 | 15 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
16 |
| - --> $DIR/reference_casting.rs:23:20 |
| 16 | + --> $DIR/reference_casting.rs:19:16 |
17 | 17 | |
|
18 |
| -LL | let _num = &mut *(num as *const i32 as *mut i32); |
19 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 18 | +LL | let _num = &mut *std::ptr::from_ref(num).cast_mut(); |
| 19 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
20 | 20 |
|
21 | 21 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
22 |
| - --> $DIR/reference_casting.rs:25:20 |
| 22 | + --> $DIR/reference_casting.rs:21:16 |
23 | 23 | |
|
24 |
| -LL | let _num = &mut *(num as *const i32).cast_mut(); |
25 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 24 | +LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut(); |
| 25 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
26 | 26 |
|
27 | 27 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
28 |
| - --> $DIR/reference_casting.rs:27:9 |
| 28 | + --> $DIR/reference_casting.rs:23:16 |
29 | 29 | |
|
30 |
| -LL | *std::ptr::from_ref(num).cast_mut() += 1; |
31 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 30 | +LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut(); |
| 31 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
32 | 32 |
|
33 | 33 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
34 |
| - --> $DIR/reference_casting.rs:29:9 |
| 34 | + --> $DIR/reference_casting.rs:25:16 |
35 | 35 | |
|
36 |
| -LL | *std::ptr::from_ref({ num }).cast_mut() += 1; |
37 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 36 | +LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32); |
| 37 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
38 | 38 |
|
39 | 39 | error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
40 |
| - --> $DIR/reference_casting.rs:31:9 |
| 40 | + --> $DIR/reference_casting.rs:29:16 |
41 | 41 | |
|
42 |
| -LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1; |
43 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 42 | +LL | let deferred = num as *const i32 as *mut i32; |
| 43 | + | ----------------------------- casting happend here |
| 44 | +LL | let _num = &mut *deferred; |
| 45 | + | ^^^^^^^^^^^^^^ |
44 | 46 |
|
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:33:9 |
| 47 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 48 | + --> $DIR/reference_casting.rs:38:5 |
47 | 49 | |
|
48 |
| -LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1; |
49 |
| - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 50 | +LL | *(a as *const _ as *mut _) = String::from("Replaced"); |
| 51 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
50 | 52 |
|
51 |
| -error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` |
52 |
| - --> $DIR/reference_casting.rs:36:9 |
| 53 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 54 | + --> $DIR/reference_casting.rs:40:5 |
| 55 | + | |
| 56 | +LL | *(a as *const _ as *mut String) += " world"; |
| 57 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 58 | + |
| 59 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 60 | + --> $DIR/reference_casting.rs:42:5 |
| 61 | + | |
| 62 | +LL | *std::ptr::from_ref(num).cast_mut() += 1; |
| 63 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 64 | + |
| 65 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 66 | + --> $DIR/reference_casting.rs:44:5 |
| 67 | + | |
| 68 | +LL | *std::ptr::from_ref({ num }).cast_mut() += 1; |
| 69 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 70 | + |
| 71 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 72 | + --> $DIR/reference_casting.rs:46:5 |
| 73 | + | |
| 74 | +LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1; |
| 75 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 76 | + |
| 77 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 78 | + --> $DIR/reference_casting.rs:48:5 |
| 79 | + | |
| 80 | +LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1; |
| 81 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 82 | + |
| 83 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 84 | + --> $DIR/reference_casting.rs:51:5 |
53 | 85 | |
|
54 |
| -LL | let value = num as *const i32 as *mut i32; |
55 |
| - | ----------------------------- casting happend here |
56 |
| -LL | *value = 1; |
57 |
| - | ^^^^^^^^^^ |
| 86 | +LL | let value = num as *const i32 as *mut i32; |
| 87 | + | ----------------------------- casting happend here |
| 88 | +LL | *value = 1; |
| 89 | + | ^^^^^^^^^^ |
58 | 90 |
|
59 |
| -error: aborting due to 9 previous errors |
| 91 | +error: aborting due to 14 previous errors |
60 | 92 |
|
0 commit comments