@@ -158,95 +158,104 @@ LL | let _num = &mut *num;
158158 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
159159
160160error: 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
162171 |
163172LL | &mut *((this as *const _) as *mut _)
164173 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165174 |
166175 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
167176
168177error: 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
170179 |
171180LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
172181 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173182 |
174183 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
175184
176185error: 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
178187 |
179188LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
180189 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181190 |
182191 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
183192
184193error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
185- --> $DIR/reference_casting.rs:88 :5
194+ --> $DIR/reference_casting.rs:92 :5
186195 |
187196LL | *(a as *const _ as *mut _) = String::from("Replaced");
188197 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189198 |
190199 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
191200
192201error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
193- --> $DIR/reference_casting.rs:90 :5
202+ --> $DIR/reference_casting.rs:94 :5
194203 |
195204LL | *(a as *const _ as *mut String) += " world";
196205 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197206 |
198207 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
199208
200209error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
201- --> $DIR/reference_casting.rs:92 :5
210+ --> $DIR/reference_casting.rs:96 :5
202211 |
203212LL | *std::ptr::from_ref(num).cast_mut() += 1;
204213 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
205214 |
206215 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
207216
208217error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
209- --> $DIR/reference_casting.rs:94 :5
218+ --> $DIR/reference_casting.rs:98 :5
210219 |
211220LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
212221 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213222 |
214223 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
215224
216225error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
217- --> $DIR/reference_casting.rs:96 :5
226+ --> $DIR/reference_casting.rs:100 :5
218227 |
219228LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
220229 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221230 |
222231 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
223232
224233error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
225- --> $DIR/reference_casting.rs:98 :5
234+ --> $DIR/reference_casting.rs:102 :5
226235 |
227236LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
228237 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229238 |
230239 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
231240
232241error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
233- --> $DIR/reference_casting.rs:100 :5
242+ --> $DIR/reference_casting.rs:104 :5
234243 |
235244LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
236245 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237246 |
238247 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
239248
240249error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
241- --> $DIR/reference_casting.rs:102 :5
250+ --> $DIR/reference_casting.rs:106 :5
242251 |
243252LL | *(std::mem::transmute::<_, *mut i32>(num) as *mut i32) += 1;
244253 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245254 |
246255 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
247256
248257error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
249- --> $DIR/reference_casting.rs:104 :5
258+ --> $DIR/reference_casting.rs:108 :5
250259 |
251260LL | / std::ptr::write(
252261LL | |
@@ -258,7 +267,16 @@ LL | | );
258267 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
259268
260269error: 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
262280 |
263281LL | let value = num as *const i32 as *mut i32;
264282 | ----------------------------- casting happend here
@@ -268,7 +286,7 @@ LL | *value = 1;
268286 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
269287
270288error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
271- --> $DIR/reference_casting.rs:114 :5
289+ --> $DIR/reference_casting.rs:120 :5
272290 |
273291LL | let value = num as *const i32 as *mut i32;
274292 | ----------------------------- casting happend here
@@ -279,23 +297,23 @@ LL | *value_rebind = 1;
279297 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
280298
281299error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
282- --> $DIR/reference_casting.rs:116 :5
300+ --> $DIR/reference_casting.rs:122 :5
283301 |
284302LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
285303 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286304 |
287305 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
288306
289307error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
290- --> $DIR/reference_casting.rs:118 :5
308+ --> $DIR/reference_casting.rs:124 :5
291309 |
292310LL | *(num as *const _ as usize as *mut i32) = 2;
293311 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
294312 |
295313 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
296314
297315error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
298- --> $DIR/reference_casting.rs:120 :5
316+ --> $DIR/reference_casting.rs:126 :5
299317 |
300318LL | let value = num as *const i32 as *mut i32;
301319 | ----------------------------- casting happend here
@@ -306,7 +324,7 @@ LL | std::ptr::write(value, 2);
306324 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
307325
308326error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
309- --> $DIR/reference_casting.rs:122 :5
327+ --> $DIR/reference_casting.rs:128 :5
310328 |
311329LL | let value = num as *const i32 as *mut i32;
312330 | ----------------------------- casting happend here
@@ -317,7 +335,7 @@ LL | std::ptr::write_unaligned(value, 2);
317335 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
318336
319337error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
320- --> $DIR/reference_casting.rs:124 :5
338+ --> $DIR/reference_casting.rs:130 :5
321339 |
322340LL | let value = num as *const i32 as *mut i32;
323341 | ----------------------------- casting happend here
@@ -328,12 +346,12 @@ LL | std::ptr::write_volatile(value, 2);
328346 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
329347
330348error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
331- --> $DIR/reference_casting.rs:128 :9
349+ --> $DIR/reference_casting.rs:134 :9
332350 |
333351LL | *(this as *const _ as *mut _) = a;
334352 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335353 |
336354 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
337355
338- error: aborting due to 38 previous errors
356+ error: aborting due to 40 previous errors
339357
0 commit comments