Skip to content

Commit e42e6f9

Browse files
ProcMacroProcessExpander: support attribute macros
1 parent 403ed48 commit e42e6f9

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

crates/proc_macro_api/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander {
4242
fn expand(
4343
&self,
4444
subtree: &Subtree,
45-
_attr: Option<&Subtree>,
45+
attr: Option<&Subtree>,
4646
) -> Result<Subtree, tt::ExpansionError> {
47-
self.process.custom_derive(&self.dylib_path, subtree, &self.name)
47+
let task = ExpansionTask {
48+
macro_body: subtree.clone(),
49+
macro_name: self.name.to_string(),
50+
attributes: attr.cloned(),
51+
lib: self.dylib_path.to_path_buf(),
52+
};
53+
54+
let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?;
55+
Ok(result.expansion)
4856
}
4957
}
5058

crates/proc_macro_api/src/process.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use std::{
1010
};
1111

1212
use crossbeam_channel::{bounded, Receiver, Sender};
13-
use tt::Subtree;
1413

1514
use crate::{
1615
msg::{ErrorCode, Message, Request, Response, ResponseError},
17-
rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind},
16+
rpc::{ListMacrosResult, ListMacrosTask, ProcMacroKind},
1817
};
1918

2019
#[derive(Debug, Default)]
@@ -58,23 +57,6 @@ impl ProcMacroProcessSrv {
5857
Ok(result.macros)
5958
}
6059

61-
pub(crate) fn custom_derive(
62-
&self,
63-
dylib_path: &Path,
64-
subtree: &Subtree,
65-
derive_name: &str,
66-
) -> Result<Subtree, tt::ExpansionError> {
67-
let task = ExpansionTask {
68-
macro_body: subtree.clone(),
69-
macro_name: derive_name.to_string(),
70-
attributes: None,
71-
lib: dylib_path.to_path_buf(),
72-
};
73-
74-
let result: ExpansionResult = self.send_task(Request::ExpansionMacro(task))?;
75-
Ok(result.expansion)
76-
}
77-
7860
pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
7961
where
8062
R: TryFrom<Response, Error = &'static str>,

0 commit comments

Comments
 (0)