From 033acc4a590092d36e5139c2297ea8dde9d43247 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 9 Dec 2020 17:22:54 -0800 Subject: [PATCH 1/2] Add test of bracketed paste inside of attribute --- tests/test_attr.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_attr.rs b/tests/test_attr.rs index 01abbfe..f2a5bf0 100644 --- a/tests/test_attr.rs +++ b/tests/test_attr.rs @@ -12,11 +12,15 @@ fn test_attr() { #[::paste_test_suite::paste_test(k = "val" "ue")] struct C; + + #[paste_test(k = "va" [] e)] + struct D; } let _ = A; let _ = B; let _ = C; + let _ = D; } #[test] From 2942f6bd6f44d29ed98ecbd35ee1496167400bf8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 9 Dec 2020 17:24:43 -0800 Subject: [PATCH 2/2] Preprocess bracketed paste inside of attribute args --- src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 01d6070..794ef3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,15 +208,12 @@ fn expand(input: TokenStream, contains_paste: &mut bool) -> Result *contains_paste = true; } else { let mut group_contains_paste = false; - let nested = match delimiter { - Delimiter::Bracket if lookbehind == Lookbehind::Pound => { - expand_attr(content, span, &mut group_contains_paste)? - } - Delimiter::Bracket if lookbehind == Lookbehind::PoundBang => { - expand_attr(content, span, &mut group_contains_paste)? - } - _ => expand(content, &mut group_contains_paste)?, - }; + let mut nested = expand(content, &mut group_contains_paste)?; + if delimiter == Delimiter::Bracket + && (lookbehind == Lookbehind::Pound || lookbehind == Lookbehind::PoundBang) + { + nested = expand_attr(nested, span, &mut group_contains_paste)? + } let group = if group_contains_paste { let mut group = Group::new(delimiter, nested); group.set_span(span);