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.rs51
1 files changed, 22 insertions, 29 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 50d248674..2a45479a8 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -38,7 +38,7 @@ use itertools::Itertools;
38use crate::{ 38use crate::{
39 db::HirDatabase, 39 db::HirDatabase,
40 display::HirDisplay, 40 display::HirDisplay,
41 primitive::{FloatTy, IntTy}, 41 primitive::{FloatTy, IntTy, UintTy},
42 utils::{generics, make_mut_slice, Generics}, 42 utils::{generics, make_mut_slice, Generics},
43}; 43};
44 44
@@ -58,23 +58,24 @@ pub enum Lifetime {
58 Static, 58 Static,
59} 59}
60 60
61/// Types of scalar values.
62#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
63#[allow(missing_docs)]
64pub enum Scalar {
65 Bool,
66 Char,
67 Int(IntTy),
68 Uint(UintTy),
69 Float(FloatTy),
70}
71
61/// A type constructor or type name: this might be something like the primitive 72/// A type constructor or type name: this might be something like the primitive
62/// type `bool`, a struct like `Vec`, or things like function pointers or 73/// type `bool`, a struct like `Vec`, or things like function pointers or
63/// tuples. 74/// tuples.
64#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] 75#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
65pub enum TypeCtor { 76pub enum TypeCtor {
66 /// The primitive boolean type. Written as `bool`. 77 /// a scalar type like `bool` or `u32`
67 Bool, 78 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 79
79 /// Structures, enumerations and unions. 80 /// Structures, enumerations and unions.
80 Adt(AdtId), 81 Adt(AdtId),
@@ -152,10 +153,7 @@ pub enum TypeCtor {
152impl TypeCtor { 153impl TypeCtor {
153 pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { 154 pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize {
154 match self { 155 match self {
155 TypeCtor::Bool 156 TypeCtor::Scalar(_)
156 | TypeCtor::Char
157 | TypeCtor::Int(_)
158 | TypeCtor::Float(_)
159 | TypeCtor::Str 157 | TypeCtor::Str
160 | TypeCtor::Never => 0, 158 | TypeCtor::Never => 0,
161 TypeCtor::Slice 159 TypeCtor::Slice
@@ -197,10 +195,7 @@ impl TypeCtor {
197 195
198 pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> { 196 pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> {
199 match self { 197 match self {
200 TypeCtor::Bool 198 TypeCtor::Scalar(_)
201 | TypeCtor::Char
202 | TypeCtor::Int(_)
203 | TypeCtor::Float(_)
204 | TypeCtor::Str 199 | TypeCtor::Str
205 | TypeCtor::Never 200 | TypeCtor::Never
206 | TypeCtor::Slice 201 | TypeCtor::Slice
@@ -232,10 +227,7 @@ impl TypeCtor {
232 227
233 pub fn as_generic_def(self) -> Option<GenericDefId> { 228 pub fn as_generic_def(self) -> Option<GenericDefId> {
234 match self { 229 match self {
235 TypeCtor::Bool 230 TypeCtor::Scalar(_)
236 | TypeCtor::Char
237 | TypeCtor::Int(_)
238 | TypeCtor::Float(_)
239 | TypeCtor::Str 231 | TypeCtor::Str
240 | TypeCtor::Never 232 | TypeCtor::Never
241 | TypeCtor::Slice 233 | TypeCtor::Slice
@@ -741,11 +733,12 @@ impl Ty {
741 } 733 }
742 pub fn builtin(builtin: BuiltinType) -> Self { 734 pub fn builtin(builtin: BuiltinType) -> Self {
743 Ty::simple(match builtin { 735 Ty::simple(match builtin {
744 BuiltinType::Char => TypeCtor::Char, 736 BuiltinType::Char => TypeCtor::Scalar(Scalar::Char),
745 BuiltinType::Bool => TypeCtor::Bool, 737 BuiltinType::Bool => TypeCtor::Scalar(Scalar::Bool),
746 BuiltinType::Str => TypeCtor::Str, 738 BuiltinType::Str => TypeCtor::Str,
747 BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), 739 BuiltinType::Int(t) => TypeCtor::Scalar(Scalar::Int(t.into())),
748 BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), 740 BuiltinType::Uint(t) => TypeCtor::Scalar(Scalar::Uint(t.into())),
741 BuiltinType::Float(t) => TypeCtor::Scalar(Scalar::Float(t.into())),
749 }) 742 })
750 } 743 }
751 744