diff options
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index f7ce2e26d..b39d7fb7a 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | use std::{collections::hash_map::Entry, mem, sync::Arc}; | 3 | use std::{collections::hash_map::Entry, mem, sync::Arc}; |
4 | 4 | ||
5 | use arena::map::ArenaMap; | ||
6 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId}; | 5 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId}; |
7 | use smallvec::SmallVec; | 6 | use smallvec::SmallVec; |
8 | use syntax::{ | 7 | use syntax::{ |
@@ -85,8 +84,7 @@ impl Ctx { | |||
85 | | ast::Item::Fn(_) | 84 | | ast::Item::Fn(_) |
86 | | ast::Item::TypeAlias(_) | 85 | | ast::Item::TypeAlias(_) |
87 | | ast::Item::Const(_) | 86 | | ast::Item::Const(_) |
88 | | ast::Item::Static(_) | 87 | | ast::Item::Static(_) => { |
89 | | ast::Item::MacroCall(_) => { | ||
90 | // Skip this if we're already collecting inner items. We'll descend into all nodes | 88 | // Skip this if we're already collecting inner items. We'll descend into all nodes |
91 | // already. | 89 | // already. |
92 | if !inner { | 90 | if !inner { |
@@ -99,7 +97,11 @@ impl Ctx { | |||
99 | ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {} | 97 | ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {} |
100 | 98 | ||
101 | // These don't have inner items. | 99 | // These don't have inner items. |
102 | ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {} | 100 | ast::Item::Module(_) |
101 | | ast::Item::ExternCrate(_) | ||
102 | | ast::Item::Use(_) | ||
103 | | ast::Item::MacroCall(_) | ||
104 | | ast::Item::MacroRules(_) => {} | ||
103 | }; | 105 | }; |
104 | 106 | ||
105 | let attrs = Attrs::new(item, &self.hygiene); | 107 | let attrs = Attrs::new(item, &self.hygiene); |
@@ -119,6 +121,7 @@ impl Ctx { | |||
119 | )), | 121 | )), |
120 | ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into), | 122 | ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into), |
121 | ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), | 123 | ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), |
124 | ast::Item::MacroRules(ast) => self.lower_macro_rules(ast).map(Into::into), | ||
122 | ast::Item::ExternBlock(ast) => { | 125 | ast::Item::ExternBlock(ast) => { |
123 | Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>())) | 126 | Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>())) |
124 | } | 127 | } |
@@ -526,9 +529,15 @@ impl Ctx { | |||
526 | } | 529 | } |
527 | 530 | ||
528 | fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { | 531 | fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { |
529 | let name = m.name().map(|it| it.as_name()); | ||
530 | let attrs = Attrs::new(m, &self.hygiene); | ||
531 | let path = ModPath::from_src(m.path()?, &self.hygiene)?; | 532 | let path = ModPath::from_src(m.path()?, &self.hygiene)?; |
533 | let ast_id = self.source_ast_id_map.ast_id(m); | ||
534 | let res = MacroCall { path, ast_id }; | ||
535 | Some(id(self.data().macro_calls.alloc(res))) | ||
536 | } | ||
537 | |||
538 | fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> { | ||
539 | let name = m.name().map(|it| it.as_name())?; | ||
540 | let attrs = Attrs::new(m, &self.hygiene); | ||
532 | 541 | ||
533 | let ast_id = self.source_ast_id_map.ast_id(m); | 542 | let ast_id = self.source_ast_id_map.ast_id(m); |
534 | 543 | ||
@@ -548,8 +557,8 @@ impl Ctx { | |||
548 | }; | 557 | }; |
549 | 558 | ||
550 | let is_builtin = attrs.by_key("rustc_builtin_macro").exists(); | 559 | let is_builtin = attrs.by_key("rustc_builtin_macro").exists(); |
551 | let res = MacroCall { name, path, is_export, is_builtin, is_local_inner, ast_id }; | 560 | let res = MacroRules { name, is_export, is_builtin, is_local_inner, ast_id }; |
552 | Some(id(self.data().macro_calls.alloc(res))) | 561 | Some(id(self.data().macro_rules.alloc(res))) |
553 | } | 562 | } |
554 | 563 | ||
555 | fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> Vec<ModItem> { | 564 | fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> Vec<ModItem> { |
@@ -607,7 +616,7 @@ impl Ctx { | |||
607 | owner: GenericsOwner<'_>, | 616 | owner: GenericsOwner<'_>, |
608 | node: &impl ast::GenericParamsOwner, | 617 | node: &impl ast::GenericParamsOwner, |
609 | ) -> GenericParamsId { | 618 | ) -> GenericParamsId { |
610 | let mut sm = &mut ArenaMap::default(); | 619 | let mut sm = &mut Default::default(); |
611 | let mut generics = GenericParams::default(); | 620 | let mut generics = GenericParams::default(); |
612 | match owner { | 621 | match owner { |
613 | GenericsOwner::Function(func) => { | 622 | GenericsOwner::Function(func) => { |
@@ -630,7 +639,7 @@ impl Ctx { | |||
630 | default: None, | 639 | default: None, |
631 | provenance: TypeParamProvenance::TraitSelf, | 640 | provenance: TypeParamProvenance::TraitSelf, |
632 | }); | 641 | }); |
633 | sm.insert(self_param_id, Either::Left(trait_def.clone())); | 642 | sm.type_params.insert(self_param_id, Either::Left(trait_def.clone())); |
634 | // add super traits as bounds on Self | 643 | // add super traits as bounds on Self |
635 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 644 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
636 | let self_param = TypeRef::Path(name![Self].into()); | 645 | let self_param = TypeRef::Path(name![Self].into()); |