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