mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
ProcMacroProcessExpander: support attribute macros
This commit is contained in:
parent
403ed489ff
commit
e42e6f9ab9
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<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>,
|
||||
|
Loading…
Reference in New Issue
Block a user