aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/primitive.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-20 22:08:30 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-20 22:08:30 +0000
commit1eb3bf41d75a8c744a0ecb586d4a2e92a1175c08 (patch)
tree6c2ddb0c296c566e9074eb316fafdce8807bcef2 /crates/ra_hir/src/ty/primitive.rs
parent8b61ea127c596e4305acffa0d9180e48bd57f6c4 (diff)
parentf5165af9a7cdf9e43db0a95e717a47fa2bdf6c25 (diff)
Merge #1003
1003: make Name::new private r=flodiebold a=matklad This maybe is overengineering, but it seems cool to keep names completely opaque. r? @flodiebold Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/primitive.rs')
-rw-r--r--crates/ra_hir/src/ty/primitive.rs66
1 files changed, 54 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs
index 30aeac48e..421f7e980 100644
--- a/crates/ra_hir/src/ty/primitive.rs
+++ b/crates/ra_hir/src/ty/primitive.rs
@@ -10,10 +10,20 @@ pub enum UncertainIntTy {
10} 10}
11 11
12impl UncertainIntTy { 12impl UncertainIntTy {
13 pub fn from_name(name: &Name) -> Option<UncertainIntTy> { 13 pub(crate) fn from_type_name(name: &Name) -> Option<UncertainIntTy> {
14 if let Some(ty) = IntTy::from_name(name) { 14 if let Some(ty) = IntTy::from_type_name(name) {
15 Some(UncertainIntTy::Signed(ty)) 15 Some(UncertainIntTy::Signed(ty))
16 } else if let Some(ty) = UintTy::from_name(name) { 16 } else if let Some(ty) = UintTy::from_type_name(name) {
17 Some(UncertainIntTy::Unsigned(ty))
18 } else {
19 None
20 }
21 }
22
23 pub(crate) fn from_suffix(suffix: &str) -> Option<UncertainIntTy> {
24 if let Some(ty) = IntTy::from_suffix(suffix) {
25 Some(UncertainIntTy::Signed(ty))
26 } else if let Some(ty) = UintTy::from_suffix(suffix) {
17 Some(UncertainIntTy::Unsigned(ty)) 27 Some(UncertainIntTy::Unsigned(ty))
18 } else { 28 } else {
19 None 29 None
@@ -38,12 +48,12 @@ pub enum UncertainFloatTy {
38} 48}
39 49
40impl UncertainFloatTy { 50impl UncertainFloatTy {
41 pub fn from_name(name: &Name) -> Option<UncertainFloatTy> { 51 pub(crate) fn from_type_name(name: &Name) -> Option<UncertainFloatTy> {
42 if let Some(ty) = FloatTy::from_name(name) { 52 FloatTy::from_type_name(name).map(UncertainFloatTy::Known)
43 Some(UncertainFloatTy::Known(ty)) 53 }
44 } else { 54
45 None 55 pub(crate) fn from_suffix(suffix: &str) -> Option<UncertainFloatTy> {
46 } 56 FloatTy::from_suffix(suffix).map(UncertainFloatTy::Known)
47 } 57 }
48} 58}
49 59
@@ -87,7 +97,7 @@ impl fmt::Display for IntTy {
87} 97}
88 98
89impl IntTy { 99impl IntTy {
90 pub fn from_name(name: &Name) -> Option<IntTy> { 100 fn from_type_name(name: &Name) -> Option<IntTy> {
91 match name.as_known_name()? { 101 match name.as_known_name()? {
92 KnownName::Isize => Some(IntTy::Isize), 102 KnownName::Isize => Some(IntTy::Isize),
93 KnownName::I8 => Some(IntTy::I8), 103 KnownName::I8 => Some(IntTy::I8),
@@ -98,6 +108,18 @@ impl IntTy {
98 _ => None, 108 _ => None,
99 } 109 }
100 } 110 }
111
112 fn from_suffix(suffix: &str) -> Option<IntTy> {
113 match suffix {
114 "isize" => Some(IntTy::Isize),
115 "i8" => Some(IntTy::I8),
116 "i16" => Some(IntTy::I16),
117 "i32" => Some(IntTy::I32),
118 "i64" => Some(IntTy::I64),
119 "i128" => Some(IntTy::I128),
120 _ => None,
121 }
122 }
101} 123}
102 124
103#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] 125#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
@@ -125,7 +147,7 @@ impl fmt::Display for UintTy {
125} 147}
126 148
127impl UintTy { 149impl UintTy {
128 pub fn from_name(name: &Name) -> Option<UintTy> { 150 fn from_type_name(name: &Name) -> Option<UintTy> {
129 match name.as_known_name()? { 151 match name.as_known_name()? {
130 KnownName::Usize => Some(UintTy::Usize), 152 KnownName::Usize => Some(UintTy::Usize),
131 KnownName::U8 => Some(UintTy::U8), 153 KnownName::U8 => Some(UintTy::U8),
@@ -136,6 +158,18 @@ impl UintTy {
136 _ => None, 158 _ => None,
137 } 159 }
138 } 160 }
161
162 fn from_suffix(suffix: &str) -> Option<UintTy> {
163 match suffix {
164 "usize" => Some(UintTy::Usize),
165 "u8" => Some(UintTy::U8),
166 "u16" => Some(UintTy::U16),
167 "u32" => Some(UintTy::U32),
168 "u64" => Some(UintTy::U64),
169 "u128" => Some(UintTy::U128),
170 _ => None,
171 }
172 }
139} 173}
140 174
141impl fmt::Debug for UintTy { 175impl fmt::Debug for UintTy {
@@ -170,11 +204,19 @@ impl FloatTy {
170 } 204 }
171 } 205 }
172 206
173 pub fn from_name(name: &Name) -> Option<FloatTy> { 207 fn from_type_name(name: &Name) -> Option<FloatTy> {
174 match name.as_known_name()? { 208 match name.as_known_name()? {
175 KnownName::F32 => Some(FloatTy::F32), 209 KnownName::F32 => Some(FloatTy::F32),
176 KnownName::F64 => Some(FloatTy::F64), 210 KnownName::F64 => Some(FloatTy::F64),
177 _ => None, 211 _ => None,
178 } 212 }
179 } 213 }
214
215 fn from_suffix(suffix: &str) -> Option<FloatTy> {
216 match suffix {
217 "f32" => Some(FloatTy::F32),
218 "f64" => Some(FloatTy::F64),
219 _ => None,
220 }
221 }
180} 222}