@@ -112,95 +112,117 @@ LL | let _num = &mut *deferred;
112112 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
113113
114114error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
115- --> $DIR/reference_casting.rs:50:16
115+ --> $DIR/reference_casting.rs:51:16
116+ |
117+ LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
118+ | ---------------------------------------------------------------------------- casting happend here
119+ ...
120+ LL | let _num = &mut *deferred_rebind;
121+ | ^^^^^^^^^^^^^^^^^^^^^
122+ |
123+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
124+
125+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
126+ --> $DIR/reference_casting.rs:53:16
116127 |
117128LL | let _num = &mut *(num as *const _ as usize as *mut i32);
118129 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119130 |
120131 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
121132
122133error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
123- --> $DIR/reference_casting.rs:54:9
134+ --> $DIR/reference_casting.rs:60:16
135+ |
136+ LL | let num = NUM as *const i32 as *mut i32;
137+ | ----------------------------- casting happend here
138+ ...
139+ LL | let _num = &mut *num;
140+ | ^^^^^^^^^
141+ |
142+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
143+
144+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
145+ --> $DIR/reference_casting.rs:64:9
124146 |
125147LL | &mut *((this as *const _) as *mut _)
126148 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127149 |
128150 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
129151
130152error: 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
153+ --> $DIR/reference_casting.rs:69 :18
132154 |
133155LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
134156 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135157 |
136158 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
137159
138160error: 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
161+ --> $DIR/reference_casting.rs:74 :18
140162 |
141163LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
142164 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143165 |
144166 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
145167
146168error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
147- --> $DIR/reference_casting.rs:74 :5
169+ --> $DIR/reference_casting.rs:84 :5
148170 |
149171LL | *(a as *const _ as *mut _) = String::from("Replaced");
150172 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151173 |
152174 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
153175
154176error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
155- --> $DIR/reference_casting.rs:76 :5
177+ --> $DIR/reference_casting.rs:86 :5
156178 |
157179LL | *(a as *const _ as *mut String) += " world";
158180 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159181 |
160182 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
161183
162184error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
163- --> $DIR/reference_casting.rs:78 :5
185+ --> $DIR/reference_casting.rs:88 :5
164186 |
165187LL | *std::ptr::from_ref(num).cast_mut() += 1;
166188 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167189 |
168190 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
169191
170192error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
171- --> $DIR/reference_casting.rs:80 :5
193+ --> $DIR/reference_casting.rs:90 :5
172194 |
173195LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
174196 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175197 |
176198 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
177199
178200error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
179- --> $DIR/reference_casting.rs:82 :5
201+ --> $DIR/reference_casting.rs:92 :5
180202 |
181203LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
182204 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
183205 |
184206 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
185207
186208error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
187- --> $DIR/reference_casting.rs:84 :5
209+ --> $DIR/reference_casting.rs:94 :5
188210 |
189211LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
190212 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191213 |
192214 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
193215
194216error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
195- --> $DIR/reference_casting.rs:86 :5
217+ --> $DIR/reference_casting.rs:96 :5
196218 |
197219LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
198220 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
199221 |
200222 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
201223
202224error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
203- --> $DIR/reference_casting.rs:88 :5
225+ --> $DIR/reference_casting.rs:98 :5
204226 |
205227LL | / std::ptr::write(
206228LL | |
@@ -212,7 +234,7 @@ LL | | );
212234 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
213235
214236error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
215- --> $DIR/reference_casting.rs:95 :5
237+ --> $DIR/reference_casting.rs:105 :5
216238 |
217239LL | let value = num as *const i32 as *mut i32;
218240 | ----------------------------- casting happend here
@@ -222,23 +244,34 @@ LL | *value = 1;
222244 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
223245
224246error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
225- --> $DIR/reference_casting.rs:97:5
247+ --> $DIR/reference_casting.rs:108:5
248+ |
249+ LL | let value = num as *const i32 as *mut i32;
250+ | ----------------------------- casting happend here
251+ ...
252+ LL | *value_rebind = 1;
253+ | ^^^^^^^^^^^^^^^^^
254+ |
255+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
256+
257+ error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
258+ --> $DIR/reference_casting.rs:110:5
226259 |
227260LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
228261 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229262 |
230263 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
231264
232265error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
233- --> $DIR/reference_casting.rs:99 :5
266+ --> $DIR/reference_casting.rs:112 :5
234267 |
235268LL | *(num as *const _ as usize as *mut i32) = 2;
236269 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237270 |
238271 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
239272
240273error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
241- --> $DIR/reference_casting.rs:101 :5
274+ --> $DIR/reference_casting.rs:114 :5
242275 |
243276LL | let value = num as *const i32 as *mut i32;
244277 | ----------------------------- casting happend here
@@ -249,7 +282,7 @@ LL | std::ptr::write(value, 2);
249282 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
250283
251284error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
252- --> $DIR/reference_casting.rs:103 :5
285+ --> $DIR/reference_casting.rs:116 :5
253286 |
254287LL | let value = num as *const i32 as *mut i32;
255288 | ----------------------------- casting happend here
@@ -260,7 +293,7 @@ LL | std::ptr::write_unaligned(value, 2);
260293 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
261294
262295error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
263- --> $DIR/reference_casting.rs:105 :5
296+ --> $DIR/reference_casting.rs:118 :5
264297 |
265298LL | let value = num as *const i32 as *mut i32;
266299 | ----------------------------- casting happend here
@@ -271,12 +304,12 @@ LL | std::ptr::write_volatile(value, 2);
271304 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
272305
273306error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
274- --> $DIR/reference_casting.rs:109 :9
307+ --> $DIR/reference_casting.rs:122 :9
275308 |
276309LL | *(this as *const _ as *mut _) = a;
277310 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
278311 |
279312 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
280313
281- error: aborting due to 32 previous errors
314+ error: aborting due to 35 previous errors
282315
0 commit comments