diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres/raw.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 39b011ad7..f2716a295 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -156,9 +156,16 @@ pub(super) struct DefData { | |||
156 | } | 156 | } |
157 | 157 | ||
158 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 158 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
159 | pub(super) enum StructDefKind { | ||
160 | Record, | ||
161 | Tuple, | ||
162 | Unit, | ||
163 | } | ||
164 | |||
165 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
159 | pub(super) enum DefKind { | 166 | pub(super) enum DefKind { |
160 | Function(FileAstId<ast::FnDef>), | 167 | Function(FileAstId<ast::FnDef>), |
161 | Struct(FileAstId<ast::StructDef>), | 168 | Struct(FileAstId<ast::StructDef>, StructDefKind), |
162 | Union(FileAstId<ast::UnionDef>), | 169 | Union(FileAstId<ast::UnionDef>), |
163 | Enum(FileAstId<ast::EnumDef>), | 170 | Enum(FileAstId<ast::EnumDef>), |
164 | Const(FileAstId<ast::ConstDef>), | 171 | Const(FileAstId<ast::ConstDef>), |
@@ -171,7 +178,7 @@ impl DefKind { | |||
171 | pub fn ast_id(&self) -> FileAstId<ast::ModuleItem> { | 178 | pub fn ast_id(&self) -> FileAstId<ast::ModuleItem> { |
172 | match self { | 179 | match self { |
173 | DefKind::Function(it) => it.upcast(), | 180 | DefKind::Function(it) => it.upcast(), |
174 | DefKind::Struct(it) => it.upcast(), | 181 | DefKind::Struct(it, _) => it.upcast(), |
175 | DefKind::Union(it) => it.upcast(), | 182 | DefKind::Union(it) => it.upcast(), |
176 | DefKind::Enum(it) => it.upcast(), | 183 | DefKind::Enum(it) => it.upcast(), |
177 | DefKind::Const(it) => it.upcast(), | 184 | DefKind::Const(it) => it.upcast(), |
@@ -188,6 +195,7 @@ pub(super) struct MacroData { | |||
188 | pub(super) path: ModPath, | 195 | pub(super) path: ModPath, |
189 | pub(super) name: Option<Name>, | 196 | pub(super) name: Option<Name>, |
190 | pub(super) export: bool, | 197 | pub(super) export: bool, |
198 | pub(super) local_inner: bool, | ||
191 | pub(super) builtin: bool, | 199 | pub(super) builtin: bool, |
192 | } | 200 | } |
193 | 201 | ||
@@ -235,9 +243,14 @@ impl RawItemsCollector { | |||
235 | return; | 243 | return; |
236 | } | 244 | } |
237 | ast::ModuleItem::StructDef(it) => { | 245 | ast::ModuleItem::StructDef(it) => { |
246 | let kind = match it.kind() { | ||
247 | ast::StructKind::Record(_) => StructDefKind::Record, | ||
248 | ast::StructKind::Tuple(_) => StructDefKind::Tuple, | ||
249 | ast::StructKind::Unit => StructDefKind::Unit, | ||
250 | }; | ||
238 | let id = self.source_ast_id_map.ast_id(&it); | 251 | let id = self.source_ast_id_map.ast_id(&it); |
239 | let name = it.name(); | 252 | let name = it.name(); |
240 | (DefKind::Struct(id), name) | 253 | (DefKind::Struct(id, kind), name) |
241 | } | 254 | } |
242 | ast::ModuleItem::UnionDef(it) => { | 255 | ast::ModuleItem::UnionDef(it) => { |
243 | let id = self.source_ast_id_map.ast_id(&it); | 256 | let id = self.source_ast_id_map.ast_id(&it); |
@@ -401,14 +414,32 @@ impl RawItemsCollector { | |||
401 | 414 | ||
402 | let name = m.name().map(|it| it.as_name()); | 415 | let name = m.name().map(|it| it.as_name()); |
403 | let ast_id = self.source_ast_id_map.ast_id(&m); | 416 | let ast_id = self.source_ast_id_map.ast_id(&m); |
404 | // FIXME: cfg_attr | ||
405 | let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); | ||
406 | 417 | ||
407 | // FIXME: cfg_attr | 418 | // FIXME: cfg_attr |
408 | let builtin = | 419 | let export_attr = attrs.by_key("macro_export"); |
409 | m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "rustc_builtin_macro"); | 420 | |
421 | let export = export_attr.exists(); | ||
422 | let local_inner = if export { | ||
423 | export_attr.tt_values().map(|it| &it.token_trees).flatten().any(|it| match it { | ||
424 | tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => { | ||
425 | ident.text.contains("local_inner_macros") | ||
426 | } | ||
427 | _ => false, | ||
428 | }) | ||
429 | } else { | ||
430 | false | ||
431 | }; | ||
432 | |||
433 | let builtin = attrs.by_key("rustc_builtin_macro").exists(); | ||
410 | 434 | ||
411 | let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export, builtin }); | 435 | let m = self.raw_items.macros.alloc(MacroData { |
436 | ast_id, | ||
437 | path, | ||
438 | name, | ||
439 | export, | ||
440 | local_inner, | ||
441 | builtin, | ||
442 | }); | ||
412 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); | 443 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); |
413 | } | 444 | } |
414 | 445 | ||