]>
git.proxmox.com Git - rustc.git/blob - src/librustc_const_math/is.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.
14 /// Depending on the target only one variant is ever used in a compilation.
15 /// Anything else is an error. This invariant is checked at several locations
16 #[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, Hash, Eq, PartialEq)]
21 pub use self::ConstIsize
::*;
24 pub fn as_i64(self, target_int_ty
: ast
::IntTy
) -> i64 {
25 match (self, target_int_ty
) {
26 (Is32(i
), ast
::IntTy
::I32
) => i
as i64,
27 (Is64(i
), ast
::IntTy
::I64
) => i
,
28 _
=> panic
!("got invalid isize size for target"),
31 pub fn new(i
: i64, target_int_ty
: ast
::IntTy
) -> Result
<Self, ConstMathErr
> {
33 ast
::IntTy
::I32
if i
as i32 as i64 == i
=> Ok(Is32(i
as i32)),
34 ast
::IntTy
::I32
=> Err(LitOutOfRange(ast
::IntTy
::Is
)),
35 ast
::IntTy
::I64
=> Ok(Is64(i
)),