Account for proc macro helpers when parsing attr

This commit is contained in:
Jonas Schievink 2020-10-05 23:41:16 +02:00
parent 44587d1bfc
commit 8ab7696acd
2 changed files with 9 additions and 1 deletions

View File

@ -1229,9 +1229,10 @@ fn collect_proc_macro_def(&mut self, func_name: &Name, attrs: &Attrs) {
} else { } else {
let derive = attrs.by_key("proc_macro_derive"); let derive = attrs.by_key("proc_macro_derive");
if let Some(arg) = derive.tt_values().next() { if let Some(arg) = derive.tt_values().next() {
if let [TokenTree::Leaf(Leaf::Ident(trait_name))] = &*arg.token_trees { if let [TokenTree::Leaf(Leaf::Ident(trait_name)), ..] = &*arg.token_trees {
trait_name.as_name() trait_name.as_name()
} else { } else {
log::trace!("malformed `#[proc_macro_derive]`: {}", arg);
return; return;
} }
} else { } else {

View File

@ -688,13 +688,20 @@ pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream {
pub fn derive_macro(_item: TokenStream) -> TokenStream { pub fn derive_macro(_item: TokenStream) -> TokenStream {
TokenStream TokenStream
} }
#[proc_macro_derive(AnotherTrait, attributes(helper_attr))]
pub fn derive_macro_2(_item: TokenStream) -> TokenStream {
TokenStream
}
", ",
expect![[r#" expect![[r#"
crate crate
AnotherTrait: m
DummyTrait: m DummyTrait: m
TokenStream: t v TokenStream: t v
attribute_macro: v m attribute_macro: v m
derive_macro: v derive_macro: v
derive_macro_2: v
function_like_macro: v m function_like_macro: v m
"#]], "#]],
); );