aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/primitive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/primitive.rs')
-rw-r--r--crates/ra_hir/src/ty/primitive.rs42
1 files changed, 22 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs
index ad79b17e4..498d42d52 100644
--- a/crates/ra_hir/src/ty/primitive.rs
+++ b/crates/ra_hir/src/ty/primitive.rs
@@ -1,5 +1,7 @@
1use std::fmt; 1use std::fmt;
2 2
3use crate::{Name, KnownName};
4
3#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] 5#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
4pub enum IntTy { 6pub enum IntTy {
5 Isize, 7 Isize,
@@ -34,14 +36,14 @@ impl IntTy {
34 } 36 }
35 } 37 }
36 38
37 pub fn from_string(s: &str) -> Option<IntTy> { 39 pub fn from_name(name: &Name) -> Option<IntTy> {
38 match s { 40 match name.as_known_name()? {
39 "isize" => Some(IntTy::Isize), 41 KnownName::Isize => Some(IntTy::Isize),
40 "i8" => Some(IntTy::I8), 42 KnownName::I8 => Some(IntTy::I8),
41 "i16" => Some(IntTy::I16), 43 KnownName::I16 => Some(IntTy::I16),
42 "i32" => Some(IntTy::I32), 44 KnownName::I32 => Some(IntTy::I32),
43 "i64" => Some(IntTy::I64), 45 KnownName::I64 => Some(IntTy::I64),
44 "i128" => Some(IntTy::I128), 46 KnownName::I128 => Some(IntTy::I128),
45 _ => None, 47 _ => None,
46 } 48 }
47 } 49 }
@@ -69,14 +71,14 @@ impl UintTy {
69 } 71 }
70 } 72 }
71 73
72 pub fn from_string(s: &str) -> Option<UintTy> { 74 pub fn from_name(name: &Name) -> Option<UintTy> {
73 match s { 75 match name.as_known_name()? {
74 "usize" => Some(UintTy::Usize), 76 KnownName::Usize => Some(UintTy::Usize),
75 "u8" => Some(UintTy::U8), 77 KnownName::U8 => Some(UintTy::U8),
76 "u16" => Some(UintTy::U16), 78 KnownName::U16 => Some(UintTy::U16),
77 "u32" => Some(UintTy::U32), 79 KnownName::U32 => Some(UintTy::U32),
78 "u64" => Some(UintTy::U64), 80 KnownName::U64 => Some(UintTy::U64),
79 "u128" => Some(UintTy::U128), 81 KnownName::U128 => Some(UintTy::U128),
80 _ => None, 82 _ => None,
81 } 83 }
82 } 84 }
@@ -120,10 +122,10 @@ impl FloatTy {
120 } 122 }
121 } 123 }
122 124
123 pub fn from_string(s: &str) -> Option<FloatTy> { 125 pub fn from_name(name: &Name) -> Option<FloatTy> {
124 match s { 126 match name.as_known_name()? {
125 "f32" => Some(FloatTy::F32), 127 KnownName::F32 => Some(FloatTy::F32),
126 "f64" => Some(FloatTy::F64), 128 KnownName::F64 => Some(FloatTy::F64),
127 _ => None, 129 _ => None,
128 } 130 }
129 } 131 }