Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/hir-def/src/nameres/collector.rs | 4 | ||||
| -rw-r--r-- | crates/hir-def/src/nameres/tests/incremental.rs | 10 | ||||
| -rw-r--r-- | crates/hir-expand/src/db.rs | 16 | ||||
| -rw-r--r-- | crates/hir-expand/src/declarative.rs | 8 | ||||
| -rw-r--r-- | crates/hir-expand/src/lib.rs | 6 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 2 |
6 files changed, 18 insertions, 28 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 25daf2c3f9..0fefef1230 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -2561,7 +2561,7 @@ impl ModCollector<'_, '_> { } else { // Case 2: normal `macro_rules!` macro let id = InFile::new(self.file_id(), ast_id); - let decl_expander = self.def_collector.db.decl_macro_expander(krate, id.upcast()); + let decl_expander = id.upcast().decl_macro_expander(self.def_collector.db, krate); let styles = decl_expander.mac.rule_styles(); MacroExpander::Declarative { styles } }; @@ -2639,7 +2639,7 @@ impl ModCollector<'_, '_> { } else { // Case 2: normal `macro` let id = InFile::new(self.file_id(), ast_id); - let decl_expander = self.def_collector.db.decl_macro_expander(krate, id.upcast()); + let decl_expander = id.upcast().decl_macro_expander(self.def_collector.db, krate); let styles = decl_expander.mac.rule_styles(); MacroExpander::Declarative { styles } }; diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs index 8e339fa973..39ef72c40b 100644 --- a/crates/hir-def/src/nameres/tests/incremental.rs +++ b/crates/hir-def/src/nameres/tests/incremental.rs @@ -227,7 +227,7 @@ pub struct S {} "HirFileId::ast_id_map_", "parse", "real_span_map", - "DeclarativeMacroExpander::expander_", + "AstId < ast :: Macro >::decl_macro_expander_", "file_item_tree_query", "HirFileId::ast_id_map_", "parse", @@ -415,7 +415,7 @@ pub struct S {} "HirFileId::ast_id_map_", "parse", "real_span_map", - "DeclarativeMacroExpander::expander_", + "AstId < ast :: Macro >::decl_macro_expander_", "file_item_tree_query", "HirFileId::ast_id_map_", "parse", @@ -429,7 +429,7 @@ pub struct S {} "HirFileId::ast_id_map_", "MacroCallId::parse_macro_expansion_", "MacroCallId::macro_arg_", - "DeclarativeMacroExpander::expander_", + "AstId < ast :: Macro >::decl_macro_expander_", "macro_def_shim", "file_item_tree_query", "HirFileId::ast_id_map_", @@ -451,7 +451,7 @@ pub struct S {} "file_item_tree_query", "real_span_map", "MacroCallId::macro_arg_", - "DeclarativeMacroExpander::expander_", + "AstId < ast :: Macro >::decl_macro_expander_", "MacroCallId::macro_arg_", "MacroCallId::macro_arg_", ] @@ -526,7 +526,7 @@ m!(Z); "HirFileId::ast_id_map_", "parse", "real_span_map", - "DeclarativeMacroExpander::expander_", + "AstId < ast :: Macro >::decl_macro_expander_", "file_item_tree_query", "HirFileId::ast_id_map_", "parse", diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 2edbd30dcf..d9e17cfb2d 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -1,18 +1,6 @@ //! Defines database & queries for macro expansion. -use base_db::{Crate, SourceDatabase}; -use syntax::ast; - -use crate::{AstId, declarative::DeclarativeMacroExpander}; +use base_db::SourceDatabase; #[query_group::query_group] -pub trait ExpandDatabase: SourceDatabase { - /// Fetches (and compiles) the expander of this decl macro. - #[salsa::invoke(DeclarativeMacroExpander::expander)] - #[salsa::transparent] - fn decl_macro_expander( - &self, - def_crate: Crate, - id: AstId<ast::Macro>, - ) -> &DeclarativeMacroExpander; -} +pub trait ExpandDatabase: SourceDatabase {} diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs index 5ba30f1256..c250bc5270 100644 --- a/crates/hir-expand/src/declarative.rs +++ b/crates/hir-expand/src/declarative.rs @@ -80,13 +80,15 @@ impl DeclarativeMacroExpander { } #[salsa::tracked] -impl DeclarativeMacroExpander { +impl AstId<ast::Macro> { + /// Fetches (and compiles) the expander of this decl macro. #[salsa::tracked(returns(ref))] - pub(crate) fn expander( + pub fn decl_macro_expander( + self, db: &dyn ExpandDatabase, def_crate: Crate, - id: AstId<ast::Macro>, ) -> DeclarativeMacroExpander { + let id = self; let (root, map) = id.file_id.parse_with_map(db); let root = root.syntax_node(); diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 9d648b12a2..293d73fb2d 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -673,7 +673,7 @@ impl MacroCallId { let arg = macro_arg; let res = match loc.def.kind { MacroDefKind::Declarative(id, _) => { - db.decl_macro_expander(loc.def.krate, id).expand(db, arg, self, span) + id.decl_macro_expander(db, loc.def.krate).expand(db, arg, self, span) } MacroDefKind::BuiltIn(_, it) => { it.expand(db, self, arg, span).map_err(Into::into).zip_val(None) @@ -915,8 +915,8 @@ impl MacroCallId { MacroDefKind::BuiltInAttr(_, it) if it.is_derive() => { pseudo_derive_attr_expansion(&tt, attr_arg.as_ref()?, span) } - MacroDefKind::Declarative(it, _) => db - .decl_macro_expander(loc.krate, it) + MacroDefKind::Declarative(it, _) => it + .decl_macro_expander(db, loc.krate) .expand_unhygienic(db, &tt, loc.kind.call_style(), span), MacroDefKind::BuiltIn(_, it) => it.expand(db, self, &tt, span).map_err(Into::into), MacroDefKind::BuiltInDerive(_, it) => { diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index a78ce2a2ab..4793959fa0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1190,7 +1190,7 @@ fn emit_macro_def_diagnostics<'db>( let id = db.macro_def(m.id); let krate = id.krate; if let hir_expand::MacroDefKind::Declarative(ast, _) = id.kind - && let expander = db.decl_macro_expander(krate, ast) + && let expander = ast.decl_macro_expander(db, krate) && let Some(e) = expander.mac.err() { let edition = krate.data(db).edition; |