From b84efbaacfc980ba167edc145aa7ca5d738448ff Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 18 Mar 2021 15:37:14 +0100 Subject: Make MacroDefId's `AstId` mandatory when possible --- crates/hir/src/has_source.rs | 2 +- crates/hir/src/lib.rs | 3 ++- crates/hir/src/semantics/source_to_def.rs | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 262002671..5b22ab58b 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -113,7 +113,7 @@ impl HasSource for TypeAlias { impl HasSource for MacroDef { type Ast = ast::Macro; fn source(self, db: &dyn HirDatabase) -> Option> { - let ast_id = self.id.ast_id?; + let ast_id = self.id.ast_id()?; Some(InFile { file_id: ast_id.file_id, value: ast_id.to_node(db.upcast()) }) } } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index b41a36a78..b860cbf3c 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1154,7 +1154,8 @@ impl MacroDef { /// Indicate it is a derive macro pub fn is_derive_macro(&self) -> bool { - matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_)) + // FIXME: wrong for `ProcMacro` + matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..)) } } diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index c6ad5ecb5..762809fcd 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -195,12 +195,12 @@ impl SourceToDefCtx<'_, '_> { &mut self, src: InFile, ) -> Option { - let kind = MacroDefKind::Declarative; + let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); + let ast_id = AstId::new(src.file_id, file_ast_id.upcast()); + let kind = MacroDefKind::Declarative(ast_id); let file_id = src.file_id.original_file(self.db.upcast()); let krate = self.file_to_def(file_id).get(0).copied()?.krate(); - let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); - let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast())); - Some(MacroDefId { krate, ast_id, kind, local_inner: false }) + Some(MacroDefId { krate, kind, local_inner: false }) } pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option { -- cgit v1.2.3