@@ -80,7 +80,19 @@ LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
8080 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
8181
8282error: 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
8496 |
8597LL | let deferred = num as *const i32 as *mut i32;
8698 | ----------------------------- casting happend here
@@ -90,7 +102,7 @@ LL | let _num = &mut *deferred;
90102 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
91103
92104error: 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
94106 |
95107LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
96108 | ---------------------------------------------------------------------------- casting happend here
@@ -100,79 +112,95 @@ LL | let _num = &mut *deferred;
100112 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
101113
102114error: 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
104116 |
105117LL | let _num = &mut *(num as *const _ as usize as *mut i32);
106118 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107119 |
108120 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
109121
110122error: 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
112124 |
113125LL | &mut *((this as *const _) as *mut _)
114126 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115127 |
116128 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
117129
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+
118146error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
119- --> $DIR/reference_casting.rs:60 :5
147+ --> $DIR/reference_casting.rs:74 :5
120148 |
121149LL | *(a as *const _ as *mut _) = String::from("Replaced");
122150 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123151 |
124152 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
125153
126154error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
127- --> $DIR/reference_casting.rs:62 :5
155+ --> $DIR/reference_casting.rs:76 :5
128156 |
129157LL | *(a as *const _ as *mut String) += " world";
130158 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131159 |
132160 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
133161
134162error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
135- --> $DIR/reference_casting.rs:64 :5
163+ --> $DIR/reference_casting.rs:78 :5
136164 |
137165LL | *std::ptr::from_ref(num).cast_mut() += 1;
138166 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139167 |
140168 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
141169
142170error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
143- --> $DIR/reference_casting.rs:66 :5
171+ --> $DIR/reference_casting.rs:80 :5
144172 |
145173LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
146174 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147175 |
148176 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
149177
150178error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
151- --> $DIR/reference_casting.rs:68 :5
179+ --> $DIR/reference_casting.rs:82 :5
152180 |
153181LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
154182 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155183 |
156184 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
157185
158186error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
159- --> $DIR/reference_casting.rs:70 :5
187+ --> $DIR/reference_casting.rs:84 :5
160188 |
161189LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
162190 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163191 |
164192 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
165193
166194error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
167- --> $DIR/reference_casting.rs:72 :5
195+ --> $DIR/reference_casting.rs:86 :5
168196 |
169197LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
170198 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171199 |
172200 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
173201
174202error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
175- --> $DIR/reference_casting.rs:74 :5
203+ --> $DIR/reference_casting.rs:88 :5
176204 |
177205LL | / std::ptr::write(
178206LL | |
@@ -184,7 +212,7 @@ LL | | );
184212 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
185213
186214error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
187- --> $DIR/reference_casting.rs:81 :5
215+ --> $DIR/reference_casting.rs:95 :5
188216 |
189217LL | let value = num as *const i32 as *mut i32;
190218 | ----------------------------- casting happend here
@@ -194,23 +222,23 @@ LL | *value = 1;
194222 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
195223
196224error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
197- --> $DIR/reference_casting.rs:83 :5
225+ --> $DIR/reference_casting.rs:97 :5
198226 |
199227LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
200228 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201229 |
202230 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
203231
204232error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
205- --> $DIR/reference_casting.rs:85 :5
233+ --> $DIR/reference_casting.rs:99 :5
206234 |
207235LL | *(num as *const _ as usize as *mut i32) = 2;
208236 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209237 |
210238 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
211239
212240error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
213- --> $DIR/reference_casting.rs:87 :5
241+ --> $DIR/reference_casting.rs:101 :5
214242 |
215243LL | let value = num as *const i32 as *mut i32;
216244 | ----------------------------- casting happend here
@@ -221,7 +249,7 @@ LL | std::ptr::write(value, 2);
221249 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
222250
223251error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
224- --> $DIR/reference_casting.rs:89 :5
252+ --> $DIR/reference_casting.rs:103 :5
225253 |
226254LL | let value = num as *const i32 as *mut i32;
227255 | ----------------------------- casting happend here
@@ -232,7 +260,7 @@ LL | std::ptr::write_unaligned(value, 2);
232260 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
233261
234262error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
235- --> $DIR/reference_casting.rs:91 :5
263+ --> $DIR/reference_casting.rs:105 :5
236264 |
237265LL | let value = num as *const i32 as *mut i32;
238266 | ----------------------------- casting happend here
@@ -243,12 +271,12 @@ LL | std::ptr::write_volatile(value, 2);
243271 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
244272
245273error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
246- --> $DIR/reference_casting.rs:95 :9
274+ --> $DIR/reference_casting.rs:109 :9
247275 |
248276LL | *(this as *const _ as *mut _) = a;
249277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250278 |
251279 = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
252280
253- error: aborting due to 29 previous errors
281+ error: aborting due to 32 previous errors
254282
0 commit comments