]> git.lizzy.rs Git - rust.git/commitdiff
ProcMacroProcessExpander: support attribute macros
authorJonas Schievink <jonasschievink@gmail.com>
Mon, 7 Dec 2020 12:55:41 +0000 (13:55 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Mon, 7 Dec 2020 13:02:27 +0000 (14:02 +0100)
crates/proc_macro_api/src/lib.rs
crates/proc_macro_api/src/process.rs

index d5e87cf7d59cbf5c5453c2d4cf0da381714292aa..0537286dd1de076f2147c1cef76c39bc36ceb4ce 100644 (file)
@@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander {
     fn expand(
         &self,
         subtree: &Subtree,
-        _attr: Option<&Subtree>,
+        attr: Option<&Subtree>,
     ) -> Result<Subtree, tt::ExpansionError> {
-        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)
     }
 }
 
index 301888a0e09f17f50d5ff1da9e31deaf0fd63fbb..d68723ada36e82c1ea3fac4bdb7af6df9dfdf087 100644 (file)
 };
 
 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 @@ pub(crate) fn find_proc_macros(
         Ok(result.macros)
     }
 
-    pub(crate) fn custom_derive(
-        &self,
-        dylib_path: &Path,
-        subtree: &Subtree,
-        derive_name: &str,
-    ) -> Result<Subtree, tt::ExpansionError> {
-        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<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
     where
         R: TryFrom<Response, Error = &'static str>,