diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_hir_expand/src/name.rs | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (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.rs | 158 |
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 | ||
86 | impl AsName for tt::Ident { | ||
87 | fn as_name(&self) -> Name { | ||
88 | Name::resolve(&self.text) | ||
89 | } | ||
90 | } | ||
91 | |||
86 | impl AsName for ast::FieldKind { | 92 | impl 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 | 107 | pub mod known { |
102 | pub const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); | 108 | macro_rules! known_names { |
103 | pub const I8: Name = Name::new_inline_ascii(2, b"i8"); | 109 | ($($ident:ident),* $(,)?) => { |
104 | pub const I16: Name = Name::new_inline_ascii(3, b"i16"); | 110 | $( |
105 | pub const I32: Name = Name::new_inline_ascii(3, b"i32"); | 111 | #[allow(bad_style)] |
106 | pub const I64: Name = Name::new_inline_ascii(3, b"i64"); | 112 | pub const $ident: super::Name = |
107 | pub const I128: Name = Name::new_inline_ascii(4, b"i128"); | 113 | super::Name::new_inline_ascii(stringify!($ident).as_bytes()); |
108 | pub const USIZE: Name = Name::new_inline_ascii(5, b"usize"); | 114 | )* |
109 | pub const U8: Name = Name::new_inline_ascii(2, b"u8"); | 115 | }; |
110 | pub const U16: Name = Name::new_inline_ascii(3, b"u16"); | 116 | } |
111 | pub const U32: Name = Name::new_inline_ascii(3, b"u32"); | 117 | |
112 | pub const U64: Name = Name::new_inline_ascii(3, b"u64"); | 118 | known_names!( |
113 | pub const U128: Name = Name::new_inline_ascii(4, b"u128"); | 119 | // Primitives |
114 | pub const F32: Name = Name::new_inline_ascii(3, b"f32"); | 120 | isize, |
115 | pub const F64: Name = Name::new_inline_ascii(3, b"f64"); | 121 | i8, |
116 | pub const BOOL: Name = Name::new_inline_ascii(4, b"bool"); | 122 | i16, |
117 | pub const CHAR: Name = Name::new_inline_ascii(4, b"char"); | 123 | i32, |
118 | pub const STR: Name = Name::new_inline_ascii(3, b"str"); | 124 | i64, |
119 | 125 | i128, | |
120 | // Special names | 126 | usize, |
121 | pub const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); | 127 | u8, |
122 | pub const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); | 128 | u16, |
123 | pub 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, |
126 | pub const STD: Name = Name::new_inline_ascii(3, b"std"); | 132 | f32, |
127 | pub const ITER: Name = Name::new_inline_ascii(4, b"iter"); | 133 | f64, |
128 | pub const OPS: Name = Name::new_inline_ascii(3, b"ops"); | 134 | bool, |
129 | pub const FUTURE: Name = Name::new_inline_ascii(6, b"future"); | 135 | char, |
130 | pub const RESULT: Name = Name::new_inline_ascii(6, b"result"); | 136 | str, |
131 | pub 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) |
134 | pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); | 140 | std, |
135 | pub const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); | 141 | iter, |
136 | pub const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); | 142 | ops, |
137 | pub const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); | 143 | future, |
138 | pub const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); | 144 | result, |
139 | pub const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); | 145 | boxed, |
140 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); | 146 | // Components of known path (type name) |
141 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); | 147 | IntoIterator, |
142 | pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); | 148 | Item, |
143 | 149 | Try, | |
144 | // Builtin Macros | 150 | Ok, |
145 | pub const FILE_MACRO: Name = Name::new_inline_ascii(4, b"file"); | 151 | Future, |
146 | pub const COLUMN_MACRO: Name = Name::new_inline_ascii(6, b"column"); | 152 | Result, |
147 | pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(13, b"compile_error"); | 153 | Output, |
148 | pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line"); | 154 | Target, |
149 | pub 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 | |||
205 | pub use crate::name; | ||