|
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:15:16 |
| 2 | + --> $DIR/reference_casting.rs:19:16 |
3 | 3 | |
|
4 | 4 | LL | let _num = &mut *(num as *const i32 as *mut i32);
|
5 | 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:17:16 |
| 10 | + --> $DIR/reference_casting.rs:21:16 |
11 | 11 | |
|
12 | 12 | LL | let _num = &mut *(num as *const i32).cast_mut();
|
13 | 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:19:16 |
| 16 | + --> $DIR/reference_casting.rs:23:16 |
17 | 17 | |
|
18 | 18 | LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
|
19 | 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:21:16 |
| 22 | + --> $DIR/reference_casting.rs:25:16 |
23 | 23 | |
|
24 | 24 | LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
|
25 | 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:23:16 |
| 28 | + --> $DIR/reference_casting.rs:27:16 |
29 | 29 | |
|
30 | 30 | LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
|
31 | 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:25:16 |
| 34 | + --> $DIR/reference_casting.rs:29:16 |
35 | 35 | |
|
36 | 36 | LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
37 | 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:27:16 |
| 40 | + --> $DIR/reference_casting.rs:31:16 |
| 41 | + | |
| 42 | +LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut(); |
| 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:33:16 |
| 47 | + | |
| 48 | +LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut(); |
| 49 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 50 | + |
| 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:35:16 |
| 53 | + | |
| 54 | +LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32); |
| 55 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 56 | + |
| 57 | +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` |
| 58 | + --> $DIR/reference_casting.rs:37:16 |
41 | 59 | |
|
42 | 60 | LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
|
43 | 61 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
44 | 62 |
|
45 | 63 | 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 |
| 64 | + --> $DIR/reference_casting.rs:41:16 |
47 | 65 | |
|
48 | 66 | LL | let deferred = num as *const i32 as *mut i32;
|
49 | 67 | | ----------------------------- casting happend here
|
50 | 68 | LL | let _num = &mut *deferred;
|
51 | 69 | | ^^^^^^^^^^^^^^
|
52 | 70 |
|
| 71 | +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` |
| 72 | + --> $DIR/reference_casting.rs:44:16 |
| 73 | + | |
| 74 | +LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32; |
| 75 | + | ---------------------------------------------------------------------------- casting happend here |
| 76 | +LL | let _num = &mut *deferred; |
| 77 | + | ^^^^^^^^^^^^^^ |
| 78 | + |
| 79 | +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` |
| 80 | + --> $DIR/reference_casting.rs:46:16 |
| 81 | + | |
| 82 | +LL | let _num = &mut *(num as *const _ as usize as *mut i32); |
| 83 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 84 | + |
| 85 | +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` |
| 86 | + --> $DIR/reference_casting.rs:50:9 |
| 87 | + | |
| 88 | +LL | &mut *((this as *const _) as *mut _) |
| 89 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 90 | + |
53 | 91 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
54 |
| - --> $DIR/reference_casting.rs:40:5 |
| 92 | + --> $DIR/reference_casting.rs:60:5 |
55 | 93 | |
|
56 | 94 | LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
57 | 95 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
58 | 96 |
|
59 | 97 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
60 |
| - --> $DIR/reference_casting.rs:42:5 |
| 98 | + --> $DIR/reference_casting.rs:62:5 |
61 | 99 | |
|
62 | 100 | LL | *(a as *const _ as *mut String) += " world";
|
63 | 101 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
64 | 102 |
|
65 | 103 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
66 |
| - --> $DIR/reference_casting.rs:44:5 |
| 104 | + --> $DIR/reference_casting.rs:64:5 |
67 | 105 | |
|
68 | 106 | LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
69 | 107 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
70 | 108 |
|
71 | 109 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
72 |
| - --> $DIR/reference_casting.rs:46:5 |
| 110 | + --> $DIR/reference_casting.rs:66:5 |
73 | 111 | |
|
74 | 112 | LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
75 | 113 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
76 | 114 |
|
77 | 115 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
78 |
| - --> $DIR/reference_casting.rs:48:5 |
| 116 | + --> $DIR/reference_casting.rs:68:5 |
79 | 117 | |
|
80 | 118 | LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
81 | 119 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
82 | 120 |
|
83 | 121 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
84 |
| - --> $DIR/reference_casting.rs:50:5 |
| 122 | + --> $DIR/reference_casting.rs:70:5 |
85 | 123 | |
|
86 | 124 | LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
87 | 125 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
88 | 126 |
|
89 | 127 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
90 |
| - --> $DIR/reference_casting.rs:52:5 |
| 128 | + --> $DIR/reference_casting.rs:72:5 |
91 | 129 | |
|
92 | 130 | LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
|
93 | 131 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
94 | 132 |
|
95 | 133 | error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
96 |
| - --> $DIR/reference_casting.rs:56:5 |
| 134 | + --> $DIR/reference_casting.rs:76:5 |
97 | 135 | |
|
98 | 136 | LL | let value = num as *const i32 as *mut i32;
|
99 | 137 | | ----------------------------- casting happend here
|
100 | 138 | LL | *value = 1;
|
101 | 139 | | ^^^^^^^^^^
|
102 | 140 |
|
103 |
| -error: aborting due to 16 previous errors |
| 141 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 142 | + --> $DIR/reference_casting.rs:78:5 |
| 143 | + | |
| 144 | +LL | *(num as *const i32).cast::<i32>().cast_mut() = 2; |
| 145 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 146 | + |
| 147 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 148 | + --> $DIR/reference_casting.rs:80:5 |
| 149 | + | |
| 150 | +LL | *(num as *const _ as usize as *mut i32) = 2; |
| 151 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 152 | + |
| 153 | +error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` |
| 154 | + --> $DIR/reference_casting.rs:84:9 |
| 155 | + | |
| 156 | +LL | *(this as *const _ as *mut _) = a; |
| 157 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 158 | + |
| 159 | +error: aborting due to 25 previous errors |
104 | 160 |
|
0 commit comments