@@ -319,20 +319,28 @@ descriptions are equivalent.
319
319
Casting is indicated by the ` as ` keyword. A cast ` e as U ` is valid if one of the
320
320
following holds:
321
321
322
- * ` e ` has type ` T ` and ` T ` coerces to ` U ` ;
323
-
324
- * ` e ` has type ` *T ` and ` U ` is ` *U_0 ` (i.e., between any raw pointers);
325
-
326
- * ` e ` has type ` *T ` and ` U ` is ` uint ` , or vice versa;
327
-
328
- * ` e ` has type ` T ` and ` T ` and ` U ` are any numeric types;
329
-
330
- * ` e ` is a C-like enum and ` U ` is any integer type, ` bool ` ;
331
-
332
- * ` e ` has type ` T ` and ` T == u8 ` and ` U == char ` ;
333
-
334
- * ` e ` has type ` T ` and ` T == &[V, ..n] ` or ` T == &V ` and ` U == *const V ` , and
335
- similarly for the mutable variants to either ` *const V ` or ` *mut V ` .
322
+ * ` e ` has type ` T ` and ` T ` coerces to ` U ` ; * coercion-cast*
323
+ * ` e ` has type ` *T ` , ` U ` is ` *U_0 ` , and either ` U_0: Sized ` or
324
+ unsize_kind(` T ` ) = unsize_kind(` U_0 ` ); * ptr-ptr-cast*
325
+ * ` e ` has type ` *T ` and ` U ` is a numeric type, while ` T: Sized ` ; * ptr-addr-cast*
326
+ * ` e ` is an integer and ` U ` is ` *U_0 ` , while ` U_0: Sized ` ; * addr-ptr-cast*
327
+ * ` e ` has type ` T ` and ` T ` and ` U ` are any numeric types; * numeric-cast*
328
+ * ` e ` is a C-like enum and ` U ` is an integer type; * enum-cast*
329
+ * ` e ` has type ` bool ` or ` char ` and ` U ` is an integer; * prim-int-cast*
330
+ * ` e ` has type ` u8 ` and ` U ` is ` char ` ; * u8-char-cast*
331
+ * ` e ` has type ` &[T; n] ` and ` U ` is ` *const T ` ; * array-ptr-cast*
332
+ * ` e ` is a function pointer type and ` U ` has type ` *T ` ,
333
+ while ` T: Sized ` ; * fptr-ptr-cast*
334
+ * ` e ` is a function pointer type and ` U ` is an integer; * fptr-addr-cast*
335
+
336
+ where ` &.T ` and ` *T ` are references of either mutability,
337
+ and where unsize_kind(` T ` ) is the kind of the unsize info
338
+ in ` T ` - the vtable for a trait definition (e.g. ` fmt::Display ` or
339
+ ` Iterator ` , not ` Iterator<Item=u8> ` ) or a length (or ` () ` if ` T: Sized ` ).
340
+
341
+ Note that lengths are not adjusted when casting raw slices -
342
+ ` T: *const [u16] as *const [u8] ` creates a slice that only includes
343
+ half of the original memory.
336
344
337
345
Casting is not transitive, that is, even if ` e as U1 as U2 ` is a valid
338
346
expression, ` e as U2 ` is not necessarily so (in fact it will only be valid if
0 commit comments