@@ -80,7 +80,19 @@ LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
80
80
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
81
81
82
82
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
83
- --> $DIR/reference_casting.rs:41:16
83
+ --> $DIR/reference_casting.rs:39:16
84
+ |
85
+ LL | let _num = &mut *std::cell::UnsafeCell::raw_get(
86
+ | ________________^
87
+ LL | |
88
+ LL | | num as *const i32 as *const std::cell::UnsafeCell<i32>
89
+ LL | | );
90
+ | |_____^
91
+ |
92
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
93
+
94
+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
95
+ --> $DIR/reference_casting.rs:45:16
84
96
|
85
97
LL | let deferred = num as *const i32 as *mut i32;
86
98
| ----------------------------- casting happend here
@@ -90,7 +102,7 @@ LL | let _num = &mut *deferred;
90
102
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
91
103
92
104
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
93
- --> $DIR/reference_casting.rs:44 :16
105
+ --> $DIR/reference_casting.rs:48 :16
94
106
|
95
107
LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
96
108
| ---------------------------------------------------------------------------- casting happend here
@@ -100,79 +112,95 @@ LL | let _num = &mut *deferred;
100
112
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
101
113
102
114
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
103
- --> $DIR/reference_casting.rs:46 :16
115
+ --> $DIR/reference_casting.rs:50 :16
104
116
|
105
117
LL | let _num = &mut *(num as *const _ as usize as *mut i32);
106
118
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
119
|
108
120
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
109
121
110
122
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
111
- --> $DIR/reference_casting.rs:50 :9
123
+ --> $DIR/reference_casting.rs:54 :9
112
124
|
113
125
LL | &mut *((this as *const _) as *mut _)
114
126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115
127
|
116
128
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
117
129
130
+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
131
+ --> $DIR/reference_casting.rs:59:18
132
+ |
133
+ LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
134
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135
+ |
136
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
137
+
138
+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
139
+ --> $DIR/reference_casting.rs:64:18
140
+ |
141
+ LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
142
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143
+ |
144
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
145
+
118
146
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
119
- --> $DIR/reference_casting.rs:60 :5
147
+ --> $DIR/reference_casting.rs:74 :5
120
148
|
121
149
LL | *(a as *const _ as *mut _) = String::from("Replaced");
122
150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123
151
|
124
152
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
125
153
126
154
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
127
- --> $DIR/reference_casting.rs:62 :5
155
+ --> $DIR/reference_casting.rs:76 :5
128
156
|
129
157
LL | *(a as *const _ as *mut String) += " world";
130
158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131
159
|
132
160
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
133
161
134
162
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
135
- --> $DIR/reference_casting.rs:64 :5
163
+ --> $DIR/reference_casting.rs:78 :5
136
164
|
137
165
LL | *std::ptr::from_ref(num).cast_mut() += 1;
138
166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139
167
|
140
168
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
141
169
142
170
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
143
- --> $DIR/reference_casting.rs:66 :5
171
+ --> $DIR/reference_casting.rs:80 :5
144
172
|
145
173
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
146
174
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147
175
|
148
176
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
149
177
150
178
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
151
- --> $DIR/reference_casting.rs:68 :5
179
+ --> $DIR/reference_casting.rs:82 :5
152
180
|
153
181
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
154
182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155
183
|
156
184
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
157
185
158
186
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
159
- --> $DIR/reference_casting.rs:70 :5
187
+ --> $DIR/reference_casting.rs:84 :5
160
188
|
161
189
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
162
190
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163
191
|
164
192
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
165
193
166
194
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
167
- --> $DIR/reference_casting.rs:72 :5
195
+ --> $DIR/reference_casting.rs:86 :5
168
196
|
169
197
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
170
198
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171
199
|
172
200
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
173
201
174
202
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
175
- --> $DIR/reference_casting.rs:74 :5
203
+ --> $DIR/reference_casting.rs:88 :5
176
204
|
177
205
LL | / std::ptr::write(
178
206
LL | |
@@ -184,7 +212,7 @@ LL | | );
184
212
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
185
213
186
214
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
187
- --> $DIR/reference_casting.rs:81 :5
215
+ --> $DIR/reference_casting.rs:95 :5
188
216
|
189
217
LL | let value = num as *const i32 as *mut i32;
190
218
| ----------------------------- casting happend here
@@ -194,23 +222,23 @@ LL | *value = 1;
194
222
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
195
223
196
224
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
197
- --> $DIR/reference_casting.rs:83 :5
225
+ --> $DIR/reference_casting.rs:97 :5
198
226
|
199
227
LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
200
228
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201
229
|
202
230
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
203
231
204
232
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
205
- --> $DIR/reference_casting.rs:85 :5
233
+ --> $DIR/reference_casting.rs:99 :5
206
234
|
207
235
LL | *(num as *const _ as usize as *mut i32) = 2;
208
236
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209
237
|
210
238
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
211
239
212
240
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
213
- --> $DIR/reference_casting.rs:87 :5
241
+ --> $DIR/reference_casting.rs:101 :5
214
242
|
215
243
LL | let value = num as *const i32 as *mut i32;
216
244
| ----------------------------- casting happend here
@@ -221,7 +249,7 @@ LL | std::ptr::write(value, 2);
221
249
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
222
250
223
251
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
224
- --> $DIR/reference_casting.rs:89 :5
252
+ --> $DIR/reference_casting.rs:103 :5
225
253
|
226
254
LL | let value = num as *const i32 as *mut i32;
227
255
| ----------------------------- casting happend here
@@ -232,7 +260,7 @@ LL | std::ptr::write_unaligned(value, 2);
232
260
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
233
261
234
262
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
235
- --> $DIR/reference_casting.rs:91 :5
263
+ --> $DIR/reference_casting.rs:105 :5
236
264
|
237
265
LL | let value = num as *const i32 as *mut i32;
238
266
| ----------------------------- casting happend here
@@ -243,12 +271,12 @@ LL | std::ptr::write_volatile(value, 2);
243
271
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
244
272
245
273
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
246
- --> $DIR/reference_casting.rs:95 :9
274
+ --> $DIR/reference_casting.rs:109 :9
247
275
|
248
276
LL | *(this as *const _ as *mut _) = a;
249
277
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250
278
|
251
279
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
252
280
253
- error: aborting due to 29 previous errors
281
+ error: aborting due to 32 previous errors
254
282
0 commit comments