aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs45
1 files changed, 15 insertions, 30 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 50d248674..676519594 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -38,7 +38,6 @@ use itertools::Itertools;
38use crate::{ 38use crate::{
39 db::HirDatabase, 39 db::HirDatabase,
40 display::HirDisplay, 40 display::HirDisplay,
41 primitive::{FloatTy, IntTy},
42 utils::{generics, make_mut_slice, Generics}, 41 utils::{generics, make_mut_slice, Generics},
43}; 42};
44 43
@@ -50,7 +49,7 @@ pub use lower::{
50}; 49};
51pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 50pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
52 51
53pub use chalk_ir::{BoundVar, DebruijnIndex}; 52pub use chalk_ir::{BoundVar, DebruijnIndex, Scalar};
54 53
55#[derive(Clone, PartialEq, Eq, Debug, Hash)] 54#[derive(Clone, PartialEq, Eq, Debug, Hash)]
56pub enum Lifetime { 55pub enum Lifetime {
@@ -63,18 +62,8 @@ pub enum Lifetime {
63/// tuples. 62/// tuples.
64#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] 63#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
65pub enum TypeCtor { 64pub enum TypeCtor {
66 /// The primitive boolean type. Written as `bool`. 65 /// a scalar type like `bool` or `u32`
67 Bool, 66 Scalar(Scalar),
68
69 /// The primitive character type; holds a Unicode scalar value
70 /// (a non-surrogate code point). Written as `char`.
71 Char,
72
73 /// A primitive integer type. For example, `i32`.
74 Int(IntTy),
75
76 /// A primitive floating-point type. For example, `f64`.
77 Float(FloatTy),
78 67
79 /// Structures, enumerations and unions. 68 /// Structures, enumerations and unions.
80 Adt(AdtId), 69 Adt(AdtId),
@@ -152,10 +141,7 @@ pub enum TypeCtor {
152impl TypeCtor { 141impl TypeCtor {
153 pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { 142 pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize {
154 match self { 143 match self {
155 TypeCtor::Bool 144 TypeCtor::Scalar(_)
156 | TypeCtor::Char
157 | TypeCtor::Int(_)
158 | TypeCtor::Float(_)
159 | TypeCtor::Str 145 | TypeCtor::Str
160 | TypeCtor::Never => 0, 146 | TypeCtor::Never => 0,
161 TypeCtor::Slice 147 TypeCtor::Slice
@@ -197,10 +183,7 @@ impl TypeCtor {
197 183
198 pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> { 184 pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> {
199 match self { 185 match self {
200 TypeCtor::Bool 186 TypeCtor::Scalar(_)
201 | TypeCtor::Char
202 | TypeCtor::Int(_)
203 | TypeCtor::Float(_)
204 | TypeCtor::Str 187 | TypeCtor::Str
205 | TypeCtor::Never 188 | TypeCtor::Never
206 | TypeCtor::Slice 189 | TypeCtor::Slice
@@ -232,10 +215,7 @@ impl TypeCtor {
232 215
233 pub fn as_generic_def(self) -> Option<GenericDefId> { 216 pub fn as_generic_def(self) -> Option<GenericDefId> {
234 match self { 217 match self {
235 TypeCtor::Bool 218 TypeCtor::Scalar(_)
236 | TypeCtor::Char
237 | TypeCtor::Int(_)
238 | TypeCtor::Float(_)
239 | TypeCtor::Str 219 | TypeCtor::Str
240 | TypeCtor::Never 220 | TypeCtor::Never
241 | TypeCtor::Slice 221 | TypeCtor::Slice
@@ -741,11 +721,16 @@ impl Ty {
741 } 721 }
742 pub fn builtin(builtin: BuiltinType) -> Self { 722 pub fn builtin(builtin: BuiltinType) -> Self {
743 Ty::simple(match builtin { 723 Ty::simple(match builtin {
744 BuiltinType::Char => TypeCtor::Char, 724 BuiltinType::Char => TypeCtor::Scalar(Scalar::Char),
745 BuiltinType::Bool => TypeCtor::Bool, 725 BuiltinType::Bool => TypeCtor::Scalar(Scalar::Bool),
746 BuiltinType::Str => TypeCtor::Str, 726 BuiltinType::Str => TypeCtor::Str,
747 BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), 727 BuiltinType::Int(t) => TypeCtor::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))),
748 BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), 728 BuiltinType::Uint(t) => {
729 TypeCtor::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t)))
730 }
731 BuiltinType::Float(t) => {
732 TypeCtor::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t)))
733 }
749 }) 734 })
750 } 735 }
751 736