diff options
Diffstat (limited to 'crates/ra_hir_expand/src/name.rs')
-rw-r--r-- | crates/ra_hir_expand/src/name.rs | 166 |
1 files changed, 96 insertions, 70 deletions
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs index 9e68dd98d..59d8214fd 100644 --- a/crates/ra_hir_expand/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -104,73 +104,99 @@ impl AsName for ra_db::Dependency { | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | // Primitives | 107 | pub mod known { |
108 | pub const ISIZE: Name = Name::new_inline_ascii(b"isize"); | 108 | macro_rules! known_names { |
109 | pub const I8: Name = Name::new_inline_ascii(b"i8"); | 109 | ($($ident:ident),* $(,)?) => { |
110 | pub const I16: Name = Name::new_inline_ascii(b"i16"); | 110 | $( |
111 | pub const I32: Name = Name::new_inline_ascii(b"i32"); | 111 | #[allow(bad_style)] |
112 | pub const I64: Name = Name::new_inline_ascii(b"i64"); | 112 | pub const $ident: super::Name = |
113 | pub const I128: Name = Name::new_inline_ascii(b"i128"); | 113 | super::Name::new_inline_ascii(stringify!($ident).as_bytes()); |
114 | pub const USIZE: Name = Name::new_inline_ascii(b"usize"); | 114 | )* |
115 | pub const U8: Name = Name::new_inline_ascii(b"u8"); | 115 | }; |
116 | pub const U16: Name = Name::new_inline_ascii(b"u16"); | 116 | } |
117 | pub const U32: Name = Name::new_inline_ascii(b"u32"); | 117 | |
118 | pub const U64: Name = Name::new_inline_ascii(b"u64"); | 118 | known_names!( |
119 | pub const U128: Name = Name::new_inline_ascii(b"u128"); | 119 | // Primitives |
120 | pub const F32: Name = Name::new_inline_ascii(b"f32"); | 120 | isize, |
121 | pub const F64: Name = Name::new_inline_ascii(b"f64"); | 121 | i8, |
122 | pub const BOOL: Name = Name::new_inline_ascii(b"bool"); | 122 | i16, |
123 | pub const CHAR: Name = Name::new_inline_ascii(b"char"); | 123 | i32, |
124 | pub const STR: Name = Name::new_inline_ascii(b"str"); | 124 | i64, |
125 | 125 | i128, | |
126 | // Special names | 126 | usize, |
127 | pub const SELF_PARAM: Name = Name::new_inline_ascii(b"self"); | 127 | u8, |
128 | pub const SELF_TYPE: Name = Name::new_inline_ascii(b"Self"); | 128 | u16, |
129 | pub const MACRO_RULES: Name = Name::new_inline_ascii(b"macro_rules"); | 129 | u32, |
130 | 130 | u64, | |
131 | // Components of known path (value or mod name) | 131 | u128, |
132 | pub const STD: Name = Name::new_inline_ascii(b"std"); | 132 | f32, |
133 | pub const ITER: Name = Name::new_inline_ascii(b"iter"); | 133 | f64, |
134 | pub const OPS: Name = Name::new_inline_ascii(b"ops"); | 134 | bool, |
135 | pub const FUTURE: Name = Name::new_inline_ascii(b"future"); | 135 | char, |
136 | pub const RESULT: Name = Name::new_inline_ascii(b"result"); | 136 | str, |
137 | pub const BOXED: Name = Name::new_inline_ascii(b"boxed"); | 137 | // Special names |
138 | 138 | macro_rules, | |
139 | // Components of known path (type name) | 139 | // Components of known path (value or mod name) |
140 | pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(b"IntoIterator"); | 140 | std, |
141 | pub const ITEM_TYPE: Name = Name::new_inline_ascii(b"Item"); | 141 | iter, |
142 | pub const TRY_TYPE: Name = Name::new_inline_ascii(b"Try"); | 142 | ops, |
143 | pub const OK_TYPE: Name = Name::new_inline_ascii(b"Ok"); | 143 | future, |
144 | pub const FUTURE_TYPE: Name = Name::new_inline_ascii(b"Future"); | 144 | result, |
145 | pub const RESULT_TYPE: Name = Name::new_inline_ascii(b"Result"); | 145 | boxed, |
146 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(b"Output"); | 146 | // Components of known path (type name) |
147 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(b"Target"); | 147 | IntoIterator, |
148 | pub const BOX_TYPE: Name = Name::new_inline_ascii(b"Box"); | 148 | Item, |
149 | pub const RANGE_FROM_TYPE: Name = Name::new_inline_ascii(b"RangeFrom"); | 149 | Try, |
150 | pub const RANGE_FULL_TYPE: Name = Name::new_inline_ascii(b"RangeFull"); | 150 | Ok, |
151 | pub const RANGE_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeInclusive"); | 151 | Future, |
152 | pub const RANGE_TO_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeToInclusive"); | 152 | Result, |
153 | pub const RANGE_TO_TYPE: Name = Name::new_inline_ascii(b"RangeTo"); | 153 | Output, |
154 | pub const RANGE_TYPE: Name = Name::new_inline_ascii(b"Range"); | 154 | Target, |
155 | pub const NEG_TYPE: Name = Name::new_inline_ascii(b"Neg"); | 155 | Box, |
156 | pub const NOT_TYPE: Name = Name::new_inline_ascii(b"Not"); | 156 | RangeFrom, |
157 | 157 | RangeFull, | |
158 | // Builtin Macros | 158 | RangeInclusive, |
159 | pub const FILE_MACRO: Name = Name::new_inline_ascii(b"file"); | 159 | RangeToInclusive, |
160 | pub const COLUMN_MACRO: Name = Name::new_inline_ascii(b"column"); | 160 | RangeTo, |
161 | pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(b"compile_error"); | 161 | Range, |
162 | pub const LINE_MACRO: Name = Name::new_inline_ascii(b"line"); | 162 | Neg, |
163 | pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(b"stringify"); | 163 | Not, |
164 | pub const FORMAT_ARGS_MACRO: Name = Name::new_inline_ascii(b"format_args"); | 164 | // Builtin macros |
165 | pub const FORMAT_ARGS_NL_MACRO: Name = Name::new_inline_ascii(b"format_args_nl"); | 165 | file, |
166 | 166 | column, | |
167 | // Builtin derives | 167 | compile_error, |
168 | pub const COPY_TRAIT: Name = Name::new_inline_ascii(b"Copy"); | 168 | line, |
169 | pub const CLONE_TRAIT: Name = Name::new_inline_ascii(b"Clone"); | 169 | stringify, |
170 | pub const DEFAULT_TRAIT: Name = Name::new_inline_ascii(b"Default"); | 170 | format_args, |
171 | pub const DEBUG_TRAIT: Name = Name::new_inline_ascii(b"Debug"); | 171 | format_args_nl, |
172 | pub const HASH_TRAIT: Name = Name::new_inline_ascii(b"Hash"); | 172 | // Builtin derives |
173 | pub const ORD_TRAIT: Name = Name::new_inline_ascii(b"Ord"); | 173 | Copy, |
174 | pub const PARTIAL_ORD_TRAIT: Name = Name::new_inline_ascii(b"PartialOrd"); | 174 | Clone, |
175 | pub const EQ_TRAIT: Name = Name::new_inline_ascii(b"Eq"); | 175 | Default, |
176 | pub const PARTIAL_EQ_TRAIT: Name = Name::new_inline_ascii(b"PartialEq"); | 176 | Debug, |
177 | Hash, | ||
178 | Ord, | ||
179 | PartialOrd, | ||
180 | Eq, | ||
181 | PartialEq, | ||
182 | ); | ||
183 | |||
184 | // self/Self cannot be used as an identifier | ||
185 | pub const SELF_PARAM: super::Name = super::Name::new_inline_ascii(b"self"); | ||
186 | pub const SELF_TYPE: super::Name = super::Name::new_inline_ascii(b"Self"); | ||
187 | |||
188 | #[macro_export] | ||
189 | macro_rules! name { | ||
190 | (self) => { | ||
191 | $crate::name::known::SELF_PARAM | ||
192 | }; | ||
193 | (Self) => { | ||
194 | $crate::name::known::SELF_TYPE | ||
195 | }; | ||
196 | ($ident:ident) => { | ||
197 | $crate::name::known::$ident | ||
198 | }; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | pub use crate::name; | ||