]> git.lizzy.rs Git - rust.git/blob - src/test/ui/mismatched_types/cast-rfc0401.stderr
Rollup merge of #86747 - FabianWolff:issue-86653, r=GuillaumeGomez
[rust.git] / src / test / ui / mismatched_types / cast-rfc0401.stderr
1 error[E0606]: casting `*const U` as `*const V` is invalid
2   --> $DIR/cast-rfc0401.rs:3:5
3    |
4 LL |     u as *const V
5    |     ^^^^^^^^^^^^^
6    |
7    = note: vtable kinds may not match
8
9 error[E0606]: casting `*const U` as `*const str` is invalid
10   --> $DIR/cast-rfc0401.rs:8:5
11    |
12 LL |     u as *const str
13    |     ^^^^^^^^^^^^^^^
14    |
15    = note: vtable kinds may not match
16
17 error[E0609]: no field `f` on type `fn() {main}`
18   --> $DIR/cast-rfc0401.rs:65:18
19    |
20 LL |     let _ = main.f as *const u32;
21    |                  ^
22
23 error[E0605]: non-primitive cast: `*const u8` as `&u8`
24   --> $DIR/cast-rfc0401.rs:29:13
25    |
26 LL |     let _ = v as &u8;
27    |             ^^^^^^^^ invalid cast
28    |
29 help: consider borrowing the value
30    |
31 LL |     let _ = &*v as &u8;
32    |             ++
33
34 error[E0605]: non-primitive cast: `*const u8` as `E`
35   --> $DIR/cast-rfc0401.rs:30:13
36    |
37 LL |     let _ = v as E;
38    |             ^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
39
40 error[E0605]: non-primitive cast: `*const u8` as `fn()`
41   --> $DIR/cast-rfc0401.rs:31:13
42    |
43 LL |     let _ = v as fn();
44    |             ^^^^^^^^^ invalid cast
45
46 error[E0605]: non-primitive cast: `*const u8` as `(u32,)`
47   --> $DIR/cast-rfc0401.rs:32:13
48    |
49 LL |     let _ = v as (u32,);
50    |             ^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
51
52 error[E0605]: non-primitive cast: `Option<&*const u8>` as `*const u8`
53   --> $DIR/cast-rfc0401.rs:33:13
54    |
55 LL |     let _ = Some(&v) as *const u8;
56    |             ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
57
58 error[E0606]: casting `*const u8` as `f32` is invalid
59   --> $DIR/cast-rfc0401.rs:35:13
60    |
61 LL |     let _ = v as f32;
62    |             ^^^^^^^^
63
64 error[E0606]: casting `fn() {main}` as `f64` is invalid
65   --> $DIR/cast-rfc0401.rs:36:13
66    |
67 LL |     let _ = main as f64;
68    |             ^^^^^^^^^^^
69
70 error[E0606]: casting `&*const u8` as `usize` is invalid
71   --> $DIR/cast-rfc0401.rs:37:13
72    |
73 LL |     let _ = &v as usize;
74    |             ^^^^^^^^^^^
75    |
76    = help: cast through a raw pointer first
77
78 error[E0606]: casting `f32` as `*const u8` is invalid
79   --> $DIR/cast-rfc0401.rs:38:13
80    |
81 LL |     let _ = f as *const u8;
82    |             ^^^^^^^^^^^^^^
83
84 error[E0054]: cannot cast as `bool`
85   --> $DIR/cast-rfc0401.rs:39:13
86    |
87 LL |     let _ = 3_i32 as bool;
88    |             ^^^^^^^^^^^^^ help: compare with zero instead: `3_i32 != 0`
89
90 error[E0054]: cannot cast as `bool`
91   --> $DIR/cast-rfc0401.rs:40:13
92    |
93 LL |     let _ = E::A as bool;
94    |             ^^^^^^^^^^^^ unsupported cast
95
96 error[E0604]: only `u8` can be cast as `char`, not `u32`
97   --> $DIR/cast-rfc0401.rs:41:13
98    |
99 LL |     let _ = 0x61u32 as char;
100    |             ^^^^^^^^^^^^^^^ invalid cast
101
102 error[E0606]: casting `bool` as `f32` is invalid
103   --> $DIR/cast-rfc0401.rs:43:13
104    |
105 LL |     let _ = false as f32;
106    |             ^^^^^^^^^^^^
107    |
108    = help: cast through an integer first
109
110 error[E0606]: casting `E` as `f32` is invalid
111   --> $DIR/cast-rfc0401.rs:44:13
112    |
113 LL |     let _ = E::A as f32;
114    |             ^^^^^^^^^^^
115    |
116    = help: cast through an integer first
117
118 error[E0606]: casting `char` as `f32` is invalid
119   --> $DIR/cast-rfc0401.rs:45:13
120    |
121 LL |     let _ = 'a' as f32;
122    |             ^^^^^^^^^^
123    |
124    = help: cast through an integer first
125
126 error[E0606]: casting `bool` as `*const u8` is invalid
127   --> $DIR/cast-rfc0401.rs:47:13
128    |
129 LL |     let _ = false as *const u8;
130    |             ^^^^^^^^^^^^^^^^^^
131
132 error[E0606]: casting `E` as `*const u8` is invalid
133   --> $DIR/cast-rfc0401.rs:48:13
134    |
135 LL |     let _ = E::A as *const u8;
136    |             ^^^^^^^^^^^^^^^^^
137
138 error[E0606]: casting `char` as `*const u8` is invalid
139   --> $DIR/cast-rfc0401.rs:49:13
140    |
141 LL |     let _ = 'a' as *const u8;
142    |             ^^^^^^^^^^^^^^^^
143
144 error[E0606]: casting `usize` as `*const [u8]` is invalid
145   --> $DIR/cast-rfc0401.rs:51:13
146    |
147 LL |     let _ = 42usize as *const [u8];
148    |             ^^^^^^^^^^^^^^^^^^^^^^
149
150 error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
151   --> $DIR/cast-rfc0401.rs:52:13
152    |
153 LL |     let _ = v as *const [u8];
154    |             ^^^^^^^^^^^^^^^^
155
156 error[E0606]: casting `&dyn Foo` as `*const str` is invalid
157   --> $DIR/cast-rfc0401.rs:54:13
158    |
159 LL |     let _ = foo as *const str;
160    |             ^^^^^^^^^^^^^^^^^
161
162 error[E0606]: casting `&dyn Foo` as `*mut str` is invalid
163   --> $DIR/cast-rfc0401.rs:55:13
164    |
165 LL |     let _ = foo as *mut str;
166    |             ^^^^^^^^^^^^^^^
167
168 error[E0606]: casting `fn() {main}` as `*mut str` is invalid
169   --> $DIR/cast-rfc0401.rs:56:13
170    |
171 LL |     let _ = main as *mut str;
172    |             ^^^^^^^^^^^^^^^^
173
174 error[E0606]: casting `&f32` as `*mut f32` is invalid
175   --> $DIR/cast-rfc0401.rs:57:13
176    |
177 LL |     let _ = &f as *mut f32;
178    |             ^^^^^^^^^^^^^^
179
180 error[E0606]: casting `&f32` as `*const f64` is invalid
181   --> $DIR/cast-rfc0401.rs:58:13
182    |
183 LL |     let _ = &f as *const f64;
184    |             ^^^^^^^^^^^^^^^^
185
186 error[E0606]: casting `*const [i8]` as `usize` is invalid
187   --> $DIR/cast-rfc0401.rs:59:13
188    |
189 LL |     let _ = fat_sv as usize;
190    |             ^^^^^^^^^^^^^^^
191    |
192    = help: cast through a thin pointer first
193
194 error[E0606]: casting `*const dyn Foo` as `*const [u16]` is invalid
195   --> $DIR/cast-rfc0401.rs:68:13
196    |
197 LL |     let _ = cf as *const [u16];
198    |             ^^^^^^^^^^^^^^^^^^
199    |
200    = note: vtable kinds may not match
201
202 error[E0606]: casting `*const dyn Foo` as `*const dyn Bar` is invalid
203   --> $DIR/cast-rfc0401.rs:69:13
204    |
205 LL |     let _ = cf as *const dyn Bar;
206    |             ^^^^^^^^^^^^^^^^^^^^
207    |
208    = note: vtable kinds may not match
209
210 error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
211   --> $DIR/cast-rfc0401.rs:53:13
212    |
213 LL |     let _ = fat_v as *const dyn Foo;
214    |             ^^^^^ doesn't have a size known at compile-time
215    |
216    = help: the trait `Sized` is not implemented for `[u8]`
217    = note: required for the cast to the object type `dyn Foo`
218
219 error[E0277]: the size for values of type `str` cannot be known at compilation time
220   --> $DIR/cast-rfc0401.rs:62:13
221    |
222 LL |     let _ = a as *const dyn Foo;
223    |             ^ doesn't have a size known at compile-time
224    |
225    = help: the trait `Sized` is not implemented for `str`
226    = note: required for the cast to the object type `dyn Foo`
227
228 error[E0606]: casting `&{float}` as `f32` is invalid
229   --> $DIR/cast-rfc0401.rs:71:30
230    |
231 LL |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
232    |                              -^^^^^^^
233    |                              |
234    |                              cannot cast `&{float}` as `f32`
235    |                              help: dereference the expression: `*s`
236
237 error: aborting due to 34 previous errors
238
239 Some errors have detailed explanations: E0054, E0277, E0604, E0605, E0606, E0607, E0609.
240 For more information about an error, try `rustc --explain E0054`.