From 8ab7696acdc2f5ada5570a9ae0389a108fe19409 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 5 Oct 2020 23:41:16 +0200 Subject: Account for proc macro helpers when parsing attr --- crates/hir_def/src/nameres/collector.rs | 3 ++- crates/hir_def/src/nameres/tests/macros.rs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 100e25ffc..c8cd04264 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1229,9 +1229,10 @@ impl ModCollector<'_, '_> { } else { let derive = attrs.by_key("proc_macro_derive"); 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() } else { + log::trace!("malformed `#[proc_macro_derive]`: {}", arg); return; } } else { diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index 0851c3b7d..305fca0f9 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs @@ -688,13 +688,20 @@ fn resolves_proc_macros() { pub fn derive_macro(_item: TokenStream) -> TokenStream { TokenStream } + + #[proc_macro_derive(AnotherTrait, attributes(helper_attr))] + pub fn derive_macro_2(_item: TokenStream) -> TokenStream { + TokenStream + } ", expect![[r#" crate + AnotherTrait: m DummyTrait: m TokenStream: t v attribute_macro: v m derive_macro: v + derive_macro_2: v function_like_macro: v m "#]], ); -- cgit v1.2.3