From ea3540c1a8efb3b9c56847f831b08abb3be2d978 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 19:32:56 +0300 Subject: Store impls in CrateDefMap --- crates/ra_hir_def/src/nameres/raw.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/nameres/raw.rs') diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index f52002bc0..a0a2c7273 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -28,6 +28,7 @@ pub struct RawItems { imports: Arena, defs: Arena, macros: Arena, + impls: Arena, /// items for top-level module items: Vec, } @@ -121,6 +122,13 @@ impl Index for RawItems { } } +impl Index for RawItems { + type Output = ImplData; + fn index(&self, idx: Impl) -> &ImplData { + &self.impls[idx] + } +} + // Avoid heap allocation on items without attributes. type Attrs = Option>; @@ -142,6 +150,7 @@ pub(super) enum RawItemKind { Import(ImportId), Def(Def), Macro(Macro), + Impl(Impl), } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -203,6 +212,15 @@ pub(super) struct MacroData { pub(super) builtin: bool, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(super) struct Impl(RawId); +impl_arena_id!(Impl); + +#[derive(Debug, PartialEq, Eq)] +pub(super) struct ImplData { + pub(super) ast_id: FileAstId, +} + struct RawItemsCollector { raw_items: RawItems, source_ast_id_map: Arc, @@ -236,8 +254,8 @@ impl RawItemsCollector { self.add_extern_crate_item(current_module, extern_crate); return; } - ast::ModuleItem::ImplBlock(_) => { - // impls don't participate in name resolution + ast::ModuleItem::ImplBlock(it) => { + self.add_impl(current_module, it); return; } ast::ModuleItem::StructDef(it) => { @@ -376,6 +394,13 @@ impl RawItemsCollector { self.push_item(current_module, attrs, RawItemKind::Macro(m)); } + fn add_impl(&mut self, current_module: Option, imp: ast::ImplBlock) { + let attrs = self.parse_attrs(&imp); + let ast_id = self.source_ast_id_map.ast_id(&imp); + let imp = self.raw_items.impls.alloc(ImplData { ast_id }); + self.push_item(current_module, attrs, RawItemKind::Impl(imp)) + } + fn push_import( &mut self, current_module: Option, -- cgit v1.2.3