aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-18 14:38:04 +0000
committerGitHub <[email protected]>2021-03-18 14:38:04 +0000
commit3ab9b39dd47d99ffd97f485c27f38b8944e12a3e (patch)
tree308ffffd0b61517f13aedad9621430f4c41014e3 /crates/hir/src
parent816bc7389516dda1eb4821f2ac4d5993cd5611dd (diff)
parentb84efbaacfc980ba167edc145aa7ca5d738448ff (diff)
Merge #8087
8087: Make MacroDefId's `AstId` mandatory when possible r=jonas-schievink a=jonas-schievink This makes it clearer (in the type definition) which macros have or don't have an `AstId` bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/has_source.rs2
-rw-r--r--crates/hir/src/lib.rs3
-rw-r--r--crates/hir/src/semantics/source_to_def.rs8
3 files changed, 7 insertions, 6 deletions
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 {
113impl HasSource for MacroDef { 113impl HasSource for MacroDef {
114 type Ast = ast::Macro; 114 type Ast = ast::Macro;
115 fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> { 115 fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
116 let ast_id = self.id.ast_id?; 116 let ast_id = self.id.ast_id()?;
117 Some(InFile { file_id: ast_id.file_id, value: ast_id.to_node(db.upcast()) }) 117 Some(InFile { file_id: ast_id.file_id, value: ast_id.to_node(db.upcast()) })
118 } 118 }
119} 119}
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 {
1154 1154
1155 /// Indicate it is a derive macro 1155 /// Indicate it is a derive macro
1156 pub fn is_derive_macro(&self) -> bool { 1156 pub fn is_derive_macro(&self) -> bool {
1157 matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_)) 1157 // FIXME: wrong for `ProcMacro`
1158 matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..))
1158 } 1159 }
1159} 1160}
1160 1161
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<'_, '_> {
195 &mut self, 195 &mut self,
196 src: InFile<ast::MacroRules>, 196 src: InFile<ast::MacroRules>,
197 ) -> Option<MacroDefId> { 197 ) -> Option<MacroDefId> {
198 let kind = MacroDefKind::Declarative; 198 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value);
199 let ast_id = AstId::new(src.file_id, file_ast_id.upcast());
200 let kind = MacroDefKind::Declarative(ast_id);
199 let file_id = src.file_id.original_file(self.db.upcast()); 201 let file_id = src.file_id.original_file(self.db.upcast());
200 let krate = self.file_to_def(file_id).get(0).copied()?.krate(); 202 let krate = self.file_to_def(file_id).get(0).copied()?.krate();
201 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); 203 Some(MacroDefId { krate, kind, local_inner: false })
202 let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast()));
203 Some(MacroDefId { krate, ast_id, kind, local_inner: false })
204 } 204 }
205 205
206 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { 206 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {