aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/name.rs
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-12-23 14:35:31 +0000
committerSeivan Heidari <[email protected]>2019-12-23 14:35:31 +0000
commitb21d9337d9200e2cfdc90b386591c72c302dc03e (patch)
treef81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_hir_expand/src/name.rs
parent18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff)
parentce07a2daa9e53aa86a769f8641b14c2878444fbc (diff)
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_hir_expand/src/name.rs')
-rw-r--r--crates/ra_hir_expand/src/name.rs158
1 files changed, 107 insertions, 51 deletions
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs
index 7824489d7..e62693b68 100644
--- a/crates/ra_hir_expand/src/name.rs
+++ b/crates/ra_hir_expand/src/name.rs
@@ -38,8 +38,8 @@ impl Name {
38 } 38 }
39 39
40 /// Shortcut to create inline plain text name 40 /// Shortcut to create inline plain text name
41 const fn new_inline_ascii(len: usize, text: &[u8]) -> Name { 41 const fn new_inline_ascii(text: &[u8]) -> Name {
42 Name::new_text(SmolStr::new_inline_from_ascii(len, text)) 42 Name::new_text(SmolStr::new_inline_from_ascii(text.len(), text))
43 } 43 }
44 44
45 /// Resolve a name from the text of token. 45 /// Resolve a name from the text of token.
@@ -83,6 +83,12 @@ impl AsName for ast::Name {
83 } 83 }
84} 84}
85 85
86impl AsName for tt::Ident {
87 fn as_name(&self) -> Name {
88 Name::resolve(&self.text)
89 }
90}
91
86impl AsName for ast::FieldKind { 92impl AsName for ast::FieldKind {
87 fn as_name(&self) -> Name { 93 fn as_name(&self) -> Name {
88 match self { 94 match self {
@@ -98,52 +104,102 @@ impl AsName for ra_db::Dependency {
98 } 104 }
99} 105}
100 106
101// Primitives 107pub mod known {
102pub const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); 108 macro_rules! known_names {
103pub const I8: Name = Name::new_inline_ascii(2, b"i8"); 109 ($($ident:ident),* $(,)?) => {
104pub const I16: Name = Name::new_inline_ascii(3, b"i16"); 110 $(
105pub const I32: Name = Name::new_inline_ascii(3, b"i32"); 111 #[allow(bad_style)]
106pub const I64: Name = Name::new_inline_ascii(3, b"i64"); 112 pub const $ident: super::Name =
107pub const I128: Name = Name::new_inline_ascii(4, b"i128"); 113 super::Name::new_inline_ascii(stringify!($ident).as_bytes());
108pub const USIZE: Name = Name::new_inline_ascii(5, b"usize"); 114 )*
109pub const U8: Name = Name::new_inline_ascii(2, b"u8"); 115 };
110pub const U16: Name = Name::new_inline_ascii(3, b"u16"); 116 }
111pub const U32: Name = Name::new_inline_ascii(3, b"u32"); 117
112pub const U64: Name = Name::new_inline_ascii(3, b"u64"); 118 known_names!(
113pub const U128: Name = Name::new_inline_ascii(4, b"u128"); 119 // Primitives
114pub const F32: Name = Name::new_inline_ascii(3, b"f32"); 120 isize,
115pub const F64: Name = Name::new_inline_ascii(3, b"f64"); 121 i8,
116pub const BOOL: Name = Name::new_inline_ascii(4, b"bool"); 122 i16,
117pub const CHAR: Name = Name::new_inline_ascii(4, b"char"); 123 i32,
118pub const STR: Name = Name::new_inline_ascii(3, b"str"); 124 i64,
119 125 i128,
120// Special names 126 usize,
121pub const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); 127 u8,
122pub const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); 128 u16,
123pub const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules"); 129 u32,
124 130 u64,
125// Components of known path (value or mod name) 131 u128,
126pub const STD: Name = Name::new_inline_ascii(3, b"std"); 132 f32,
127pub const ITER: Name = Name::new_inline_ascii(4, b"iter"); 133 f64,
128pub const OPS: Name = Name::new_inline_ascii(3, b"ops"); 134 bool,
129pub const FUTURE: Name = Name::new_inline_ascii(6, b"future"); 135 char,
130pub const RESULT: Name = Name::new_inline_ascii(6, b"result"); 136 str,
131pub const BOXED: Name = Name::new_inline_ascii(5, b"boxed"); 137 // Special names
132 138 macro_rules,
133// Components of known path (type name) 139 // Components of known path (value or mod name)
134pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); 140 std,
135pub const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); 141 iter,
136pub const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); 142 ops,
137pub const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); 143 future,
138pub const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); 144 result,
139pub const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); 145 boxed,
140pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); 146 // Components of known path (type name)
141pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); 147 IntoIterator,
142pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); 148 Item,
143 149 Try,
144// Builtin Macros 150 Ok,
145pub const FILE_MACRO: Name = Name::new_inline_ascii(4, b"file"); 151 Future,
146pub const COLUMN_MACRO: Name = Name::new_inline_ascii(6, b"column"); 152 Result,
147pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(13, b"compile_error"); 153 Output,
148pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line"); 154 Target,
149pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(9, b"stringify"); 155 Box,
156 RangeFrom,
157 RangeFull,
158 RangeInclusive,
159 RangeToInclusive,
160 RangeTo,
161 Range,
162 Neg,
163 Not,
164 Index,
165 // Builtin macros
166 file,
167 column,
168 compile_error,
169 line,
170 stringify,
171 format_args,
172 format_args_nl,
173 env,
174 option_env,
175 // Builtin derives
176 Copy,
177 Clone,
178 Default,
179 Debug,
180 Hash,
181 Ord,
182 PartialOrd,
183 Eq,
184 PartialEq,
185 );
186
187 // self/Self cannot be used as an identifier
188 pub const SELF_PARAM: super::Name = super::Name::new_inline_ascii(b"self");
189 pub const SELF_TYPE: super::Name = super::Name::new_inline_ascii(b"Self");
190
191 #[macro_export]
192 macro_rules! name {
193 (self) => {
194 $crate::name::known::SELF_PARAM
195 };
196 (Self) => {
197 $crate::name::known::SELF_TYPE
198 };
199 ($ident:ident) => {
200 $crate::name::known::$ident
201 };
202 }
203}
204
205pub use crate::name;