]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | use rustc_middle::ty::{self, IntTy, Ty, TyCtxt, UintTy}; |
2 | ||
3 | /// Returns the size in bits of an integral type. | |
4 | /// Will return 0 if the type is not an int or uint variant | |
5 | pub(super) fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { | |
6 | match typ.kind() { | |
7 | ty::Int(i) => match i { | |
8 | IntTy::Isize => tcx.data_layout.pointer_size.bits(), | |
9 | IntTy::I8 => 8, | |
10 | IntTy::I16 => 16, | |
11 | IntTy::I32 => 32, | |
12 | IntTy::I64 => 64, | |
13 | IntTy::I128 => 128, | |
14 | }, | |
15 | ty::Uint(i) => match i { | |
16 | UintTy::Usize => tcx.data_layout.pointer_size.bits(), | |
17 | UintTy::U8 => 8, | |
18 | UintTy::U16 => 16, | |
19 | UintTy::U32 => 32, | |
20 | UintTy::U64 => 64, | |
21 | UintTy::U128 => 128, | |
22 | }, | |
23 | _ => 0, | |
24 | } | |
25 | } |