@@ -158,95 +158,104 @@ LL | let _num = &mut *num;
158
158
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
159
159
160
160
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
161
- --> $DIR/reference_casting.rs:68:9
161
+ --> $DIR/reference_casting.rs:68:16
162
+ |
163
+ LL | let _num = &mut *(cell as *const _ as *mut i32);
164
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165
+ |
166
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
167
+ = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
168
+
169
+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
170
+ --> $DIR/reference_casting.rs:72:9
162
171
|
163
172
LL | &mut *((this as *const _) as *mut _)
164
173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165
174
|
166
175
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
167
176
168
177
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
169
- --> $DIR/reference_casting.rs:73 :18
178
+ --> $DIR/reference_casting.rs:77 :18
170
179
|
171
180
LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
172
181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173
182
|
174
183
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
175
184
176
185
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
177
- --> $DIR/reference_casting.rs:78 :18
186
+ --> $DIR/reference_casting.rs:82 :18
178
187
|
179
188
LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
180
189
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181
190
|
182
191
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
183
192
184
193
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
185
- --> $DIR/reference_casting.rs:88 :5
194
+ --> $DIR/reference_casting.rs:92 :5
186
195
|
187
196
LL | *(a as *const _ as *mut _) = String::from("Replaced");
188
197
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189
198
|
190
199
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
191
200
192
201
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
193
- --> $DIR/reference_casting.rs:90 :5
202
+ --> $DIR/reference_casting.rs:94 :5
194
203
|
195
204
LL | *(a as *const _ as *mut String) += " world";
196
205
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197
206
|
198
207
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
199
208
200
209
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
201
- --> $DIR/reference_casting.rs:92 :5
210
+ --> $DIR/reference_casting.rs:96 :5
202
211
|
203
212
LL | *std::ptr::from_ref(num).cast_mut() += 1;
204
213
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
205
214
|
206
215
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
207
216
208
217
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
209
- --> $DIR/reference_casting.rs:94 :5
218
+ --> $DIR/reference_casting.rs:98 :5
210
219
|
211
220
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
212
221
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213
222
|
214
223
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
215
224
216
225
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
217
- --> $DIR/reference_casting.rs:96 :5
226
+ --> $DIR/reference_casting.rs:100 :5
218
227
|
219
228
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
220
229
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221
230
|
222
231
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
223
232
224
233
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
225
- --> $DIR/reference_casting.rs:98 :5
234
+ --> $DIR/reference_casting.rs:102 :5
226
235
|
227
236
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
228
237
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229
238
|
230
239
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
231
240
232
241
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
233
- --> $DIR/reference_casting.rs:100 :5
242
+ --> $DIR/reference_casting.rs:104 :5
234
243
|
235
244
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
236
245
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237
246
|
238
247
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
239
248
240
249
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
241
- --> $DIR/reference_casting.rs:102 :5
250
+ --> $DIR/reference_casting.rs:106 :5
242
251
|
243
252
LL | *(std::mem::transmute::<_, *mut i32>(num) as *mut i32) += 1;
244
253
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245
254
|
246
255
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
247
256
248
257
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
249
- --> $DIR/reference_casting.rs:104 :5
258
+ --> $DIR/reference_casting.rs:108 :5
250
259
|
251
260
LL | / std::ptr::write(
252
261
LL | |
@@ -258,7 +267,16 @@ LL | | );
258
267
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
259
268
260
269
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
261
- --> $DIR/reference_casting.rs:111:5
270
+ --> $DIR/reference_casting.rs:113:5
271
+ |
272
+ LL | *((&std::cell::UnsafeCell::new(0)) as *const _ as *mut i32) = 5;
273
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
274
+ |
275
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
276
+ = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
277
+
278
+ error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
279
+ --> $DIR/reference_casting.rs:117:5
262
280
|
263
281
LL | let value = num as *const i32 as *mut i32;
264
282
| ----------------------------- casting happend here
@@ -268,7 +286,7 @@ LL | *value = 1;
268
286
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
269
287
270
288
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
271
- --> $DIR/reference_casting.rs:114 :5
289
+ --> $DIR/reference_casting.rs:120 :5
272
290
|
273
291
LL | let value = num as *const i32 as *mut i32;
274
292
| ----------------------------- casting happend here
@@ -279,23 +297,23 @@ LL | *value_rebind = 1;
279
297
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
280
298
281
299
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
282
- --> $DIR/reference_casting.rs:116 :5
300
+ --> $DIR/reference_casting.rs:122 :5
283
301
|
284
302
LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
285
303
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286
304
|
287
305
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
288
306
289
307
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
290
- --> $DIR/reference_casting.rs:118 :5
308
+ --> $DIR/reference_casting.rs:124 :5
291
309
|
292
310
LL | *(num as *const _ as usize as *mut i32) = 2;
293
311
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
294
312
|
295
313
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
296
314
297
315
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
298
- --> $DIR/reference_casting.rs:120 :5
316
+ --> $DIR/reference_casting.rs:126 :5
299
317
|
300
318
LL | let value = num as *const i32 as *mut i32;
301
319
| ----------------------------- casting happend here
@@ -306,7 +324,7 @@ LL | std::ptr::write(value, 2);
306
324
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
307
325
308
326
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
309
- --> $DIR/reference_casting.rs:122 :5
327
+ --> $DIR/reference_casting.rs:128 :5
310
328
|
311
329
LL | let value = num as *const i32 as *mut i32;
312
330
| ----------------------------- casting happend here
@@ -317,7 +335,7 @@ LL | std::ptr::write_unaligned(value, 2);
317
335
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
318
336
319
337
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
320
- --> $DIR/reference_casting.rs:124 :5
338
+ --> $DIR/reference_casting.rs:130 :5
321
339
|
322
340
LL | let value = num as *const i32 as *mut i32;
323
341
| ----------------------------- casting happend here
@@ -328,12 +346,12 @@ LL | std::ptr::write_volatile(value, 2);
328
346
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
329
347
330
348
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
331
- --> $DIR/reference_casting.rs:128 :9
349
+ --> $DIR/reference_casting.rs:134 :9
332
350
|
333
351
LL | *(this as *const _ as *mut _) = a;
334
352
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335
353
|
336
354
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
337
355
338
- error: aborting due to 38 previous errors
356
+ error: aborting due to 40 previous errors
339
357
0 commit comments