-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
The RFC 401 cast rules are (my comments in italic):
A cast
e as U
is valid if one of the following holds:
e
has typeT
andT
coerces toU
; coerce-caste
has type*T
andU
is*U_0
(i.e., between any raw pointers); ptr-ptr-caste
has type*T
andU
isuint
, or vice versa; ptr-addr-caste
has typeT
andT
andU
are any numeric types; numeric-caste
is a C-like enum andU
is any integer type,bool
; enum-caste
has typeT
andT == u8
andU == char
; char-caste
has typeT
andT == &[V, ..n]
orT == &V
andU == *const V
, and
similarly for the mutable variants to either*const V
or*mut V
. ptr-ref-cast
The raw pointer casts (ptr-ptr-cast, ptr-addr-cast) don't make sense when only one of the pointers involved is fat (i.e. 0xb8000 as *mut [u8]
, let v=5; let u=&v; u as *const [Vec<u32>]
) – where does the vtable come from?
The casts also don't make much sense if the vtables have distinct types (say, casting *const [u8] → *const fmt::Write
– does the length turn into a vtable pointer? while this does make some sense, it is still somewhat weird).
Currently, rustc ICEs in all these casts. Some (but not all) of these ICEs are fixed in rust-lang/rust#24158.
Metadata
Metadata
Assignees
Labels
No labels