fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
15.4 KiB339 linesraw
1error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
2  --> $DIR/reference_casting.rs:19:16
3   |
4LL |     let _num = &mut *(num as *const i32 as *mut i32);
5   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6   |
7   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
8   = note: `#[deny(invalid_reference_casting)]` on by default
9
10error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
11  --> $DIR/reference_casting.rs:21:16
12   |
13LL |     let _num = &mut *(num as *const i32).cast_mut();
14   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15   |
16   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
17
18error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
19  --> $DIR/reference_casting.rs:23:16
20   |
21LL |     let _num = &mut *std::ptr::from_ref(num).cast_mut();
22   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23   |
24   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
25
26error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
27  --> $DIR/reference_casting.rs:25:16
28   |
29LL |     let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
30   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31   |
32   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
33
34error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
35  --> $DIR/reference_casting.rs:27:16
36   |
37LL |     let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
38   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39   |
40   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
41
42error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
43  --> $DIR/reference_casting.rs:29:16
44   |
45LL |     let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
46   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47   |
48   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
49
50error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
51  --> $DIR/reference_casting.rs:31:16
52   |
53LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
54   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55   |
56   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
57
58error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
59  --> $DIR/reference_casting.rs:33:16
60   |
61LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
62   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63   |
64   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
65
66error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
67  --> $DIR/reference_casting.rs:35:16
68   |
69LL |     let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
70   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71   |
72   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
73
74error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
75  --> $DIR/reference_casting.rs:37:16
76   |
77LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
78   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79   |
80   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
81
82error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
83  --> $DIR/reference_casting.rs:39:16
84   |
85LL |     let _num = &mut *(std::mem::transmute::<_, *mut i32>(num) as *mut i32);
86   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87   |
88   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
89
90error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
91  --> $DIR/reference_casting.rs:41:16
92   |
93LL |       let _num = &mut *std::cell::UnsafeCell::raw_get(
94   |  ________________^
95LL | |
96LL | |         num as *const i32 as *const std::cell::UnsafeCell<i32>
97LL | |     );
98   | |_____^
99   |
100   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
101
102error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
103  --> $DIR/reference_casting.rs:47:16
104   |
105LL |     let deferred = num as *const i32 as *mut i32;
106   |                    ----------------------------- casting happend here
107LL |     let _num = &mut *deferred;
108   |                ^^^^^^^^^^^^^^
109   |
110   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
111
112error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
113  --> $DIR/reference_casting.rs:50:16
114   |
115LL |     let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
116   |                    ---------------------------------------------------------------------------- casting happend here
117LL |     let _num = &mut *deferred;
118   |                ^^^^^^^^^^^^^^
119   |
120   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
121
122error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
123  --> $DIR/reference_casting.rs:53:16
124   |
125LL |     let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
126   |                    ---------------------------------------------------------------------------- casting happend here
127...
128LL |     let _num = &mut *deferred_rebind;
129   |                ^^^^^^^^^^^^^^^^^^^^^
130   |
131   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
132
133error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
134  --> $DIR/reference_casting.rs:55:16
135   |
136LL |     let _num = &mut *(num as *const _ as usize as *mut i32);
137   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138   |
139   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
140
141error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
142  --> $DIR/reference_casting.rs:57:16
143   |
144LL |     let _num = &mut *(std::mem::transmute::<_, *mut _>(num as *const i32) as *mut i32);
145   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146   |
147   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
148
149error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
150  --> $DIR/reference_casting.rs:64:16
151   |
152LL |     let num = NUM as *const i32 as *mut i32;
153   |               ----------------------------- casting happend here
154...
155LL |     let _num = &mut *num;
156   |                ^^^^^^^^^
157   |
158   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
159
160error: 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
162   |
163LL |         &mut *((this as *const _) as *mut _)
164   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165   |
166   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
167
168error: 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
170   |
171LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
172   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173   |
174   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
175
176error: 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
178   |
179LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
180   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181   |
182   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
183
184error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
185  --> $DIR/reference_casting.rs:88:5
186   |
187LL |     *(a as *const _ as *mut _) = String::from("Replaced");
188   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189   |
190   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
191
192error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
193  --> $DIR/reference_casting.rs:90:5
194   |
195LL |     *(a as *const _ as *mut String) += " world";
196   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197   |
198   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
199
200error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
201  --> $DIR/reference_casting.rs:92:5
202   |
203LL |     *std::ptr::from_ref(num).cast_mut() += 1;
204   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
205   |
206   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
207
208error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
209  --> $DIR/reference_casting.rs:94:5
210   |
211LL |     *std::ptr::from_ref({ num }).cast_mut() += 1;
212   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213   |
214   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
215
216error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
217  --> $DIR/reference_casting.rs:96:5
218   |
219LL |     *{ std::ptr::from_ref(num) }.cast_mut() += 1;
220   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221   |
222   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
223
224error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
225  --> $DIR/reference_casting.rs:98:5
226   |
227LL |     *(std::ptr::from_ref({ num }) as *mut i32) += 1;
228   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229   |
230   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
231
232error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
233  --> $DIR/reference_casting.rs:100:5
234   |
235LL |     *std::mem::transmute::<_, *mut i32>(num) += 1;
236   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237   |
238   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
239
240error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
241  --> $DIR/reference_casting.rs:102:5
242   |
243LL |     *(std::mem::transmute::<_, *mut i32>(num) as *mut i32) += 1;
244   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245   |
246   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
247
248error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
249  --> $DIR/reference_casting.rs:104:5
250   |
251LL | /     std::ptr::write(
252LL | |
253LL | |         std::mem::transmute::<*const i32, *mut i32>(num),
254LL | |         -1i32,
255LL | |     );
256   | |_____^
257   |
258   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
259
260error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
261  --> $DIR/reference_casting.rs:111:5
262   |
263LL |     let value = num as *const i32 as *mut i32;
264   |                 ----------------------------- casting happend here
265LL |     *value = 1;
266   |     ^^^^^^^^^^
267   |
268   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
269
270error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
271  --> $DIR/reference_casting.rs:114:5
272   |
273LL |     let value = num as *const i32 as *mut i32;
274   |                 ----------------------------- casting happend here
275...
276LL |     *value_rebind = 1;
277   |     ^^^^^^^^^^^^^^^^^
278   |
279   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
280
281error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
282  --> $DIR/reference_casting.rs:116:5
283   |
284LL |     *(num as *const i32).cast::<i32>().cast_mut() = 2;
285   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286   |
287   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
288
289error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
290  --> $DIR/reference_casting.rs:118:5
291   |
292LL |     *(num as *const _ as usize as *mut i32) = 2;
293   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
294   |
295   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
296
297error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
298  --> $DIR/reference_casting.rs:120:5
299   |
300LL |     let value = num as *const i32 as *mut i32;
301   |                 ----------------------------- casting happend here
302...
303LL |     std::ptr::write(value, 2);
304   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
305   |
306   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
307
308error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
309  --> $DIR/reference_casting.rs:122:5
310   |
311LL |     let value = num as *const i32 as *mut i32;
312   |                 ----------------------------- casting happend here
313...
314LL |     std::ptr::write_unaligned(value, 2);
315   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
316   |
317   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
318
319error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
320  --> $DIR/reference_casting.rs:124:5
321   |
322LL |     let value = num as *const i32 as *mut i32;
323   |                 ----------------------------- casting happend here
324...
325LL |     std::ptr::write_volatile(value, 2);
326   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
327   |
328   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
329
330error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
331  --> $DIR/reference_casting.rs:128:9
332   |
333LL |         *(this as *const _ as *mut _) = a;
334   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335   |
336   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
337
338error: aborting due to 38 previous errors
339