diff options
author | Haibo Huang <hhb@google.com> | 2020-12-10 12:45:42 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-10 12:45:42 +0000 |
commit | 9f76aa4f687e55976a97318b4f6a14780e8a30fe (patch) | |
tree | b224e76dae3f8fe91b0763fc30ca54fe4bf7589b | |
parent | 10e5cdba1f7862c32203ba4f4aa90c603c0d2578 (diff) | |
parent | 82c677f82621eba85fb17125fcb71d8c4a082a11 (diff) | |
download | paste-9f76aa4f687e55976a97318b4f6a14780e8a30fe.tar.gz |
Upgrade rust/crates/paste to 1.0.4 am: 2973429028 am: 82c677f826
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/paste/+/1522628
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I6154050c67a8c1af49cad70f6be21350c21a6942
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | src/attr.rs | 62 | ||||
-rw-r--r-- | src/lib.rs | 15 | ||||
-rw-r--r-- | tests/test_attr.rs | 23 |
7 files changed, 82 insertions, 36 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index f883456..5163423 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "a3e4ace7092f5f0b750efe22fe8c4b65e8495d94" + "sha1": "3eb762421182b53411e58ff93765b5604ed89c8b" } } @@ -13,7 +13,7 @@ [package] edition = "2018" name = "paste" -version = "1.0.3" +version = "1.0.4" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Macros for all your token pasting needs" readme = "README.md" @@ -25,6 +25,9 @@ targets = ["x86_64-unknown-linux-gnu"] [lib] proc-macro = true +[dev-dependencies.paste-test-suite] +version = "0" + [dev-dependencies.rustversion] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index e0b2223..ec7baa1 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "paste" -version = "1.0.3" +version = "1.0.4" authors = ["David Tolnay <dtolnay@gmail.com>"] edition = "2018" license = "MIT OR Apache-2.0" @@ -13,6 +13,7 @@ readme = "README.md" proc-macro = true [dev-dependencies] +paste-test-suite = { version = "0", path = "tests/macros" } rustversion = "1.0" trybuild = "1.0" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/paste/paste-1.0.3.crate" + value: "https://static.crates.io/crates/paste/paste-1.0.4.crate" } - version: "1.0.3" + version: "1.0.4" license_type: NOTICE last_upgrade_date { year: 2020 - month: 11 - day: 10 + month: 12 + day: 9 } } diff --git a/src/attr.rs b/src/attr.rs index 2d23730..be64a79 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -11,28 +11,50 @@ pub fn expand_attr( contains_paste: &mut bool, ) -> Result<TokenStream> { let mut tokens = attr.clone().into_iter(); - match tokens.next() { - Some(TokenTree::Ident(..)) => {} - _ => return Ok(attr), - } + let mut leading_colons = 0; // $(::)? + let mut leading_path = 0; // $($ident)::+ - let group = match tokens.next() { - Some(TokenTree::Punct(ref punct)) if punct.as_char() == '=' => { - let mut count = 0; - if tokens.inspect(|_| count += 1).all(|tt| is_stringlike(&tt)) && count > 1 { - *contains_paste = true; - return do_paste_name_value_attr(attr, span); + let mut token; + let group = loop { + token = tokens.next(); + match token { + // colon after `$(:)?` + Some(TokenTree::Punct(ref punct)) + if punct.as_char() == ':' && leading_colons < 2 && leading_path == 0 => + { + leading_colons += 1; + } + // ident after `$(::)? $($ident ::)*` + Some(TokenTree::Ident(_)) if leading_colons != 1 && leading_path % 3 == 0 => { + leading_path += 1; + } + // colon after `$(::)? $($ident ::)* $ident $(:)?` + Some(TokenTree::Punct(ref punct)) if punct.as_char() == ':' && leading_path % 3 > 0 => { + leading_path += 1; + } + // eq+value after `$(::)? $($ident)::+` + Some(TokenTree::Punct(ref punct)) + if punct.as_char() == '=' && leading_path % 3 == 1 => + { + let mut count = 0; + if tokens.inspect(|_| count += 1).all(|tt| is_stringlike(&tt)) && count > 1 { + *contains_paste = true; + let leading = leading_colons + leading_path; + return do_paste_name_value_attr(attr, span, leading); + } + return Ok(attr); } - return Ok(attr); + // parens after `$(::)? $($ident)::+` + Some(TokenTree::Group(ref group)) + if group.delimiter() == Delimiter::Parenthesis && leading_path % 3 == 1 => + { + break group; + } + // bail out + _ => return Ok(attr), } - Some(TokenTree::Group(group)) => group, - _ => return Ok(attr), }; - if group.delimiter() != Delimiter::Parenthesis { - return Ok(attr); - } - // There can't be anything else after the first group in a valid attribute. if tokens.next().is_some() { return Ok(attr); @@ -71,7 +93,7 @@ pub fn expand_attr( Ok(attr .into_iter() // Just keep the initial ident in `#[ident(...)]`. - .take(1) + .take(leading_colons + leading_path) .chain(iter::once(TokenTree::Group(group))) .collect()) } else { @@ -79,10 +101,10 @@ pub fn expand_attr( } } -fn do_paste_name_value_attr(attr: TokenStream, span: Span) -> Result<TokenStream> { +fn do_paste_name_value_attr(attr: TokenStream, span: Span, leading: usize) -> Result<TokenStream> { let mut expanded = TokenStream::new(); let mut tokens = attr.into_iter().peekable(); - expanded.extend(tokens.by_ref().take(2)); // `doc =` + expanded.extend(tokens.by_ref().take(leading + 1)); // `doc =` let mut segments = segment::parse(&mut tokens)?; @@ -208,15 +208,12 @@ fn expand(input: TokenStream, contains_paste: &mut bool) -> Result<TokenStream> *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); diff --git a/tests/test_attr.rs b/tests/test_attr.rs index fd67e2a..f2a5bf0 100644 --- a/tests/test_attr.rs +++ b/tests/test_attr.rs @@ -1,4 +1,27 @@ use paste::paste; +use paste_test_suite::paste_test; + +#[test] +fn test_attr() { + paste! { + #[paste_test(k = "val" "ue")] + struct A; + + #[paste_test_suite::paste_test(k = "val" "ue")] + struct B; + + #[::paste_test_suite::paste_test(k = "val" "ue")] + struct C; + + #[paste_test(k = "va" [<l u>] e)] + struct D; + } + + let _ = A; + let _ = B; + let _ = C; + let _ = D; +} #[test] fn test_paste_cfg() { |