Module rustc_typeck::check::cast [−][src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Code for type-checking cast expressions.
A cast e as U is valid if one of the following holds:
ehas typeTandTcoerces toU; coercion-castehas type*T,Uis*U_0, and eitherU_0: Sizedor pointer_kind(T) = pointer_kind(U_0); ptr-ptr-castehas type*TandUis a numeric type, whileT: Sized; ptr-addr-casteis an integer andUis*U_0, whileU_0: Sized; addr-ptr-castehas typeTandTandUare any numeric types; numeric-casteis a C-like enum andUis an integer type; enum-castehas typeboolorcharandUis an integer; prim-int-castehas typeu8andUischar; u8-char-castehas type&[T; n]andUis*const T; array-ptr-casteis a function pointer type andUhas type*T, whileT: Sized; fptr-ptr-casteis a function pointer type andUis an integer; fptr-addr-cast
where &.T and *T are references of either mutability,
and where pointer_kind(T) is the kind of the unsize info
in T - the vtable for a trait definition (e.g. fmt::Display or
Iterator, not Iterator<Item=u8>) or a length (or () if T: Sized).
Note that lengths are not adjusted when casting raw slices -
T: *const [u16] as *const [u8] creates a slice that only includes
half of the original memory.
Casting is not transitive, that is, even if e as U1 as U2 is a valid
expression, e as U2 is not necessarily so (in fact it will only be valid if
U1 coerces to U2).
Re-exports
use super::FnCtxt; |
use errors::DiagnosticBuilder; |
use hir::def_id::DefId; |
use lint; |
use rustc::hir; |
use rustc::session::Session; |
use rustc::traits; |
use rustc::ty; |
use rustc::ty::Ty; |
use rustc::ty::TypeFoldable; |
use rustc::ty::TypeAndMut; |
use rustc::ty::adjustment::AllowTwoPhase; |
use rustc::ty::cast::CastKind; |
use rustc::ty::cast::CastTy; |
use rustc::ty::subst::Substs; |
use rustc::middle::lang_items; |
use syntax::ast; |
use syntax_pos::Span; |
use util::common::ErrorReported; |
Structs
| CastCheck |
[ Experimental ] Reifies a cast check to be checked once we have full type information for a function context. |
Enums
| CastError |
[ Experimental ]
|
| PointerKind |
[ Experimental ] The kind of pointer and associated metadata (thin, length or vtable) - we only allow casts between fat pointers if their metadata have the same kind. |
Functions
| make_invalid_casting_error |
[ Experimental ]
|