From 8c639a87bdbd08b10d4eb84d00f25ba7bcd56be0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 29 May 2021 20:32:57 +0200 Subject: Thread proc-macro types through the HIR --- crates/hir_def/src/nameres/collector.rs | 9 +++++++-- crates/hir_def/src/nameres/proc_macro.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 4296c6304..d9d6c91a8 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -477,16 +477,21 @@ impl DefCollector<'_> { /// going out of sync with what the build system sees (since we resolve using VFS state, but /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. fn export_proc_macro(&mut self, def: ProcMacroDef, ast_id: AstId) { + let kind = def.kind.to_basedb_kind(); self.exports_proc_macros = true; let macro_def = match self.proc_macros.iter().find(|(n, _)| n == &def.name) { Some((_, expander)) => MacroDefId { krate: self.def_map.krate, - kind: MacroDefKind::ProcMacro(*expander, ast_id), + kind: MacroDefKind::ProcMacro(*expander, kind, ast_id), local_inner: false, }, None => MacroDefId { krate: self.def_map.krate, - kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate), ast_id), + kind: MacroDefKind::ProcMacro( + ProcMacroExpander::dummy(self.def_map.krate), + kind, + ast_id, + ), local_inner: false, }, }; diff --git a/crates/hir_def/src/nameres/proc_macro.rs b/crates/hir_def/src/nameres/proc_macro.rs index 156598f19..3f095d623 100644 --- a/crates/hir_def/src/nameres/proc_macro.rs +++ b/crates/hir_def/src/nameres/proc_macro.rs @@ -18,6 +18,16 @@ pub(super) enum ProcMacroKind { Attr, } +impl ProcMacroKind { + pub(super) fn to_basedb_kind(&self) -> base_db::ProcMacroKind { + match self { + ProcMacroKind::CustomDerive { .. } => base_db::ProcMacroKind::CustomDerive, + ProcMacroKind::FnLike => base_db::ProcMacroKind::FuncLike, + ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, + } + } +} + impl Attrs { #[rustfmt::skip] pub(super) fn parse_proc_macro_decl(&self, func_name: &Name) -> Option { -- cgit v1.2.3