aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/name.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand/src/name.rs')
-rw-r--r--crates/ra_hir_expand/src/name.rs166
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 107pub mod known {
108pub const ISIZE: Name = Name::new_inline_ascii(b"isize"); 108 macro_rules! known_names {
109pub const I8: Name = Name::new_inline_ascii(b"i8"); 109 ($($ident:ident),* $(,)?) => {
110pub const I16: Name = Name::new_inline_ascii(b"i16"); 110 $(
111pub const I32: Name = Name::new_inline_ascii(b"i32"); 111 #[allow(bad_style)]
112pub const I64: Name = Name::new_inline_ascii(b"i64"); 112 pub const $ident: super::Name =
113pub const I128: Name = Name::new_inline_ascii(b"i128"); 113 super::Name::new_inline_ascii(stringify!($ident).as_bytes());
114pub const USIZE: Name = Name::new_inline_ascii(b"usize"); 114 )*
115pub const U8: Name = Name::new_inline_ascii(b"u8"); 115 };
116pub const U16: Name = Name::new_inline_ascii(b"u16"); 116 }
117pub const U32: Name = Name::new_inline_ascii(b"u32"); 117
118pub const U64: Name = Name::new_inline_ascii(b"u64"); 118 known_names!(
119pub const U128: Name = Name::new_inline_ascii(b"u128"); 119 // Primitives
120pub const F32: Name = Name::new_inline_ascii(b"f32"); 120 isize,
121pub const F64: Name = Name::new_inline_ascii(b"f64"); 121 i8,
122pub const BOOL: Name = Name::new_inline_ascii(b"bool"); 122 i16,
123pub const CHAR: Name = Name::new_inline_ascii(b"char"); 123 i32,
124pub const STR: Name = Name::new_inline_ascii(b"str"); 124 i64,
125 125 i128,
126// Special names 126 usize,
127pub const SELF_PARAM: Name = Name::new_inline_ascii(b"self"); 127 u8,
128pub const SELF_TYPE: Name = Name::new_inline_ascii(b"Self"); 128 u16,
129pub 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,
132pub const STD: Name = Name::new_inline_ascii(b"std"); 132 f32,
133pub const ITER: Name = Name::new_inline_ascii(b"iter"); 133 f64,
134pub const OPS: Name = Name::new_inline_ascii(b"ops"); 134 bool,
135pub const FUTURE: Name = Name::new_inline_ascii(b"future"); 135 char,
136pub const RESULT: Name = Name::new_inline_ascii(b"result"); 136 str,
137pub 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)
140pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(b"IntoIterator"); 140 std,
141pub const ITEM_TYPE: Name = Name::new_inline_ascii(b"Item"); 141 iter,
142pub const TRY_TYPE: Name = Name::new_inline_ascii(b"Try"); 142 ops,
143pub const OK_TYPE: Name = Name::new_inline_ascii(b"Ok"); 143 future,
144pub const FUTURE_TYPE: Name = Name::new_inline_ascii(b"Future"); 144 result,
145pub const RESULT_TYPE: Name = Name::new_inline_ascii(b"Result"); 145 boxed,
146pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(b"Output"); 146 // Components of known path (type name)
147pub const TARGET_TYPE: Name = Name::new_inline_ascii(b"Target"); 147 IntoIterator,
148pub const BOX_TYPE: Name = Name::new_inline_ascii(b"Box"); 148 Item,
149pub const RANGE_FROM_TYPE: Name = Name::new_inline_ascii(b"RangeFrom"); 149 Try,
150pub const RANGE_FULL_TYPE: Name = Name::new_inline_ascii(b"RangeFull"); 150 Ok,
151pub const RANGE_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeInclusive"); 151 Future,
152pub const RANGE_TO_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeToInclusive"); 152 Result,
153pub const RANGE_TO_TYPE: Name = Name::new_inline_ascii(b"RangeTo"); 153 Output,
154pub const RANGE_TYPE: Name = Name::new_inline_ascii(b"Range"); 154 Target,
155pub const NEG_TYPE: Name = Name::new_inline_ascii(b"Neg"); 155 Box,
156pub const NOT_TYPE: Name = Name::new_inline_ascii(b"Not"); 156 RangeFrom,
157 157 RangeFull,
158// Builtin Macros 158 RangeInclusive,
159pub const FILE_MACRO: Name = Name::new_inline_ascii(b"file"); 159 RangeToInclusive,
160pub const COLUMN_MACRO: Name = Name::new_inline_ascii(b"column"); 160 RangeTo,
161pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(b"compile_error"); 161 Range,
162pub const LINE_MACRO: Name = Name::new_inline_ascii(b"line"); 162 Neg,
163pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(b"stringify"); 163 Not,
164pub const FORMAT_ARGS_MACRO: Name = Name::new_inline_ascii(b"format_args"); 164 // Builtin macros
165pub 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,
168pub const COPY_TRAIT: Name = Name::new_inline_ascii(b"Copy"); 168 line,
169pub const CLONE_TRAIT: Name = Name::new_inline_ascii(b"Clone"); 169 stringify,
170pub const DEFAULT_TRAIT: Name = Name::new_inline_ascii(b"Default"); 170 format_args,
171pub const DEBUG_TRAIT: Name = Name::new_inline_ascii(b"Debug"); 171 format_args_nl,
172pub const HASH_TRAIT: Name = Name::new_inline_ascii(b"Hash"); 172 // Builtin derives
173pub const ORD_TRAIT: Name = Name::new_inline_ascii(b"Ord"); 173 Copy,
174pub const PARTIAL_ORD_TRAIT: Name = Name::new_inline_ascii(b"PartialOrd"); 174 Clone,
175pub const EQ_TRAIT: Name = Name::new_inline_ascii(b"Eq"); 175 Default,
176pub 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
202pub use crate::name;