]>
git.proxmox.com Git - rustc.git/blob - src/librustc/ty/cast.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Helpers for handling cast expressions, used in both
18 /// Types that are represented as ints.
19 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
28 // Valid types for the result of a non-coercion cast
29 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
30 pub enum CastTy
<'tcx
> {
31 /// Various types that are represented as ints and handled mostly
32 /// in the same way, merged for easier matching.
34 /// Floating-Point types
39 Ptr(&'tcx ty
::TypeAndMut
<'tcx
>),
41 RPtr(&'tcx ty
::TypeAndMut
<'tcx
>),
44 /// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)
45 #[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
60 impl<'tcx
> CastTy
<'tcx
> {
61 pub fn from_ty(t
: Ty
<'tcx
>) -> Option
<CastTy
<'tcx
>> {
63 ty
::TyBool
=> Some(CastTy
::Int(IntTy
::Bool
)),
64 ty
::TyChar
=> Some(CastTy
::Int(IntTy
::Char
)),
65 ty
::TyInt(_
) => Some(CastTy
::Int(IntTy
::I
)),
66 ty
::TyUint(u
) => Some(CastTy
::Int(IntTy
::U(u
))),
67 ty
::TyFloat(_
) => Some(CastTy
::Float
),
68 ty
::TyEnum(d
,_
) if d
.is_payloadfree() =>
69 Some(CastTy
::Int(IntTy
::CEnum
)),
70 ty
::TyRawPtr(ref mt
) => Some(CastTy
::Ptr(mt
)),
71 ty
::TyRef(_
, ref mt
) => Some(CastTy
::RPtr(mt
)),
72 ty
::TyFnPtr(..) => Some(CastTy
::FnPtr
),