diff options
author | Lukas Wirth <[email protected]> | 2021-02-28 09:58:34 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-02-28 10:06:37 +0000 |
commit | 7c2dd85a32e320fd412a720ea5b847c66bf246ae (patch) | |
tree | fc5fb1d9ae0ae59f4d7eafe68720005d095bd360 /crates/hir_ty/src/primitive.rs | |
parent | 5183c9f08345c664237ae138e86f96ff46714f15 (diff) |
Use chalk_ir::Scalar directly
Diffstat (limited to 'crates/hir_ty/src/primitive.rs')
-rw-r--r-- | crates/hir_ty/src/primitive.rs | 147 |
1 files changed, 41 insertions, 106 deletions
diff --git a/crates/hir_ty/src/primitive.rs b/crates/hir_ty/src/primitive.rs index e727c9581..2449addfb 100644 --- a/crates/hir_ty/src/primitive.rs +++ b/crates/hir_ty/src/primitive.rs | |||
@@ -3,128 +3,63 @@ | |||
3 | //! * during type inference, they can be uncertain (ie, `let x = 92;`) | 3 | //! * during type inference, they can be uncertain (ie, `let x = 92;`) |
4 | //! * they don't belong to any particular crate. | 4 | //! * they don't belong to any particular crate. |
5 | 5 | ||
6 | use std::fmt; | 6 | pub use chalk_ir::{FloatTy, IntTy, UintTy}; |
7 | |||
8 | pub use hir_def::builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}; | 7 | pub use hir_def::builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}; |
9 | 8 | ||
10 | /// Different signed int types. | 9 | pub fn int_ty_to_string(ty: IntTy) -> &'static str { |
11 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | 10 | match ty { |
12 | pub enum IntTy { | 11 | IntTy::Isize => "isize", |
13 | Isize, | 12 | IntTy::I8 => "i8", |
14 | I8, | 13 | IntTy::I16 => "i16", |
15 | I16, | 14 | IntTy::I32 => "i32", |
16 | I32, | 15 | IntTy::I64 => "i64", |
17 | I64, | 16 | IntTy::I128 => "i128", |
18 | I128, | ||
19 | } | ||
20 | |||
21 | /// Different unsigned int types. | ||
22 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
23 | pub enum UintTy { | ||
24 | Usize, | ||
25 | U8, | ||
26 | U16, | ||
27 | U32, | ||
28 | U64, | ||
29 | U128, | ||
30 | } | ||
31 | |||
32 | impl fmt::Display for IntTy { | ||
33 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
34 | write!(f, "{}", self.ty_to_string()) | ||
35 | } | ||
36 | } | ||
37 | |||
38 | impl IntTy { | ||
39 | pub fn ty_to_string(self) -> &'static str { | ||
40 | match self { | ||
41 | IntTy::Isize => "isize", | ||
42 | IntTy::I8 => "i8", | ||
43 | IntTy::I16 => "i16", | ||
44 | IntTy::I32 => "i32", | ||
45 | IntTy::I64 => "i64", | ||
46 | IntTy::I128 => "i128", | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
51 | impl fmt::Display for UintTy { | ||
52 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
53 | write!(f, "{}", self.ty_to_string()) | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl UintTy { | ||
58 | pub fn ty_to_string(self) -> &'static str { | ||
59 | match self { | ||
60 | UintTy::Usize => "usize", | ||
61 | UintTy::U8 => "u8", | ||
62 | UintTy::U16 => "u16", | ||
63 | UintTy::U32 => "u32", | ||
64 | UintTy::U64 => "u64", | ||
65 | UintTy::U128 => "u128", | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
71 | pub enum FloatTy { | ||
72 | F32, | ||
73 | F64, | ||
74 | } | ||
75 | |||
76 | impl fmt::Debug for FloatTy { | ||
77 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
78 | fmt::Display::fmt(self, f) | ||
79 | } | 17 | } |
80 | } | 18 | } |
81 | 19 | ||
82 | impl fmt::Display for FloatTy { | 20 | pub fn uint_ty_to_string(ty: UintTy) -> &'static str { |
83 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 21 | match ty { |
84 | write!(f, "{}", self.ty_to_string()) | 22 | UintTy::Usize => "usize", |
23 | UintTy::U8 => "u8", | ||
24 | UintTy::U16 => "u16", | ||
25 | UintTy::U32 => "u32", | ||
26 | UintTy::U64 => "u64", | ||
27 | UintTy::U128 => "u128", | ||
85 | } | 28 | } |
86 | } | 29 | } |
87 | 30 | ||
88 | impl FloatTy { | 31 | pub fn float_ty_to_string(ty: FloatTy) -> &'static str { |
89 | pub fn ty_to_string(self) -> &'static str { | 32 | match ty { |
90 | match self { | 33 | FloatTy::F32 => "f32", |
91 | FloatTy::F32 => "f32", | 34 | FloatTy::F64 => "f64", |
92 | FloatTy::F64 => "f64", | ||
93 | } | ||
94 | } | 35 | } |
95 | } | 36 | } |
96 | 37 | ||
97 | impl From<BuiltinInt> for IntTy { | 38 | pub(super) fn int_ty_from_builtin(t: BuiltinInt) -> IntTy { |
98 | fn from(t: BuiltinInt) -> Self { | 39 | match t { |
99 | match t { | 40 | BuiltinInt::Isize => IntTy::Isize, |
100 | BuiltinInt::Isize => Self::Isize, | 41 | BuiltinInt::I8 => IntTy::I8, |
101 | BuiltinInt::I8 => Self::I8, | 42 | BuiltinInt::I16 => IntTy::I16, |
102 | BuiltinInt::I16 => Self::I16, | 43 | BuiltinInt::I32 => IntTy::I32, |
103 | BuiltinInt::I32 => Self::I32, | 44 | BuiltinInt::I64 => IntTy::I64, |
104 | BuiltinInt::I64 => Self::I64, | 45 | BuiltinInt::I128 => IntTy::I128, |
105 | BuiltinInt::I128 => Self::I128, | ||
106 | } | ||
107 | } | 46 | } |
108 | } | 47 | } |
109 | 48 | ||
110 | impl From<BuiltinUint> for UintTy { | 49 | pub(super) fn uint_ty_from_builtin(t: BuiltinUint) -> UintTy { |
111 | fn from(t: BuiltinUint) -> Self { | 50 | match t { |
112 | match t { | 51 | BuiltinUint::Usize => UintTy::Usize, |
113 | BuiltinUint::Usize => Self::Usize, | 52 | BuiltinUint::U8 => UintTy::U8, |
114 | BuiltinUint::U8 => Self::U8, | 53 | BuiltinUint::U16 => UintTy::U16, |
115 | BuiltinUint::U16 => Self::U16, | 54 | BuiltinUint::U32 => UintTy::U32, |
116 | BuiltinUint::U32 => Self::U32, | 55 | BuiltinUint::U64 => UintTy::U64, |
117 | BuiltinUint::U64 => Self::U64, | 56 | BuiltinUint::U128 => UintTy::U128, |
118 | BuiltinUint::U128 => Self::U128, | ||
119 | } | ||
120 | } | 57 | } |
121 | } | 58 | } |
122 | 59 | ||
123 | impl From<BuiltinFloat> for FloatTy { | 60 | pub(super) fn float_ty_from_builtin(t: BuiltinFloat) -> FloatTy { |
124 | fn from(t: BuiltinFloat) -> Self { | 61 | match t { |
125 | match t { | 62 | BuiltinFloat::F32 => FloatTy::F32, |
126 | BuiltinFloat::F32 => Self::F32, | 63 | BuiltinFloat::F64 => FloatTy::F64, |
127 | BuiltinFloat::F64 => Self::F64, | ||
128 | } | ||
129 | } | 64 | } |
130 | } | 65 | } |