From e42e6f9ab902ba05c3f534876ca6ab0dcdce13a2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 7 Dec 2020 13:55:41 +0100 Subject: ProcMacroProcessExpander: support attribute macros --- crates/proc_macro_api/src/lib.rs | 12 ++++++++++-- crates/proc_macro_api/src/process.rs | 20 +------------------- 2 files changed, 11 insertions(+), 21 deletions(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index d5e87cf7d..0537286dd 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander { fn expand( &self, subtree: &Subtree, - _attr: Option<&Subtree>, + attr: Option<&Subtree>, ) -> Result { - self.process.custom_derive(&self.dylib_path, subtree, &self.name) + let task = ExpansionTask { + macro_body: subtree.clone(), + macro_name: self.name.to_string(), + attributes: attr.cloned(), + lib: self.dylib_path.to_path_buf(), + }; + + let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?; + Ok(result.expansion) } } diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index 301888a0e..d68723ada 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -10,11 +10,10 @@ use std::{ }; use crossbeam_channel::{bounded, Receiver, Sender}; -use tt::Subtree; use crate::{ msg::{ErrorCode, Message, Request, Response, ResponseError}, - rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}, + rpc::{ListMacrosResult, ListMacrosTask, ProcMacroKind}, }; #[derive(Debug, Default)] @@ -58,23 +57,6 @@ impl ProcMacroProcessSrv { Ok(result.macros) } - pub(crate) fn custom_derive( - &self, - dylib_path: &Path, - subtree: &Subtree, - derive_name: &str, - ) -> Result { - let task = ExpansionTask { - macro_body: subtree.clone(), - macro_name: derive_name.to_string(), - attributes: None, - lib: dylib_path.to_path_buf(), - }; - - let result: ExpansionResult = self.send_task(Request::ExpansionMacro(task))?; - Ok(result.expansion) - } - pub(crate) fn send_task(&self, req: Request) -> Result where R: TryFrom, -- cgit v1.2.3