diff options
author | Joel Galenson <jgalenson@google.com> | 2021-06-23 19:44:00 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-23 19:44:00 +0000 |
commit | 755b38fe23a1375ed193eccb27afe8dd179d57a2 (patch) | |
tree | 722588656f0fbb0986a7bbcdb25f2e170eda07a9 | |
parent | c2143ad6a0a0e834b956c2ebb2be936789a83742 (diff) | |
parent | e12fd736bf17b4fa00008821be7d4f42006c1047 (diff) | |
download | async-stream-impl-755b38fe23a1375ed193eccb27afe8dd179d57a2.tar.gz |
Upgrade rust/crates/async-stream-impl to 0.3.2 am: 79381120d6 am: 6171f14fa2 am: e12fd736bf
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/async-stream-impl/+/1742396
Change-Id: I5e6f31c97fb81bfbae1271799307ffce3aa9737f
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | TEST_MAPPING | 99 | ||||
-rw-r--r-- | src/lib.rs | 92 |
7 files changed, 199 insertions, 14 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4a76e44..620b2af 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "8c22349b9367b981ad08db573d8d906069e66d8c" + "sha1": "b28da881695e3c66e1782f0c2c330d4e162eb7c2" } } @@ -33,7 +33,7 @@ rust_proc_macro { } // dependent_library ["feature_list"] -// proc-macro2-1.0.26 "default,proc-macro" +// proc-macro2-1.0.27 "default,proc-macro" // quote-1.0.9 "default,proc-macro" -// syn-1.0.72 "clone-impls,default,derive,extra-traits,full,parsing,printing,proc-macro,quote,visit-mut" +// syn-1.0.73 "clone-impls,default,derive,extra-traits,full,parsing,printing,proc-macro,quote,visit-mut" // unicode-xid-0.2.2 "default" @@ -13,11 +13,11 @@ [package] edition = "2018" name = "async-stream-impl" -version = "0.3.1" +version = "0.3.2" authors = ["Carl Lerche <me@carllerche.com>"] description = "proc macros for async-stream crate" homepage = "https://github.com/tokio-rs/async-stream" -documentation = "https://docs.rs/async-stream-impl/0.3" +documentation = "https://docs.rs/async-stream-impl" license = "MIT" repository = "https://github.com/tokio-rs/async-stream" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 6682921..4317fdf 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,11 +1,11 @@ [package] name = "async-stream-impl" -version = "0.3.1" +version = "0.3.2" edition = "2018" license = "MIT" authors = ["Carl Lerche <me@carllerche.com>"] description = "proc macros for async-stream crate" -documentation = "https://docs.rs/async-stream-impl/0.3" +documentation = "https://docs.rs/async-stream-impl" homepage = "https://github.com/tokio-rs/async-stream" repository = "https://github.com/tokio-rs/async-stream" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/async-stream-impl/async-stream-impl-0.3.1.crate" + value: "https://static.crates.io/crates/async-stream-impl/async-stream-impl-0.3.2.crate" } - version: "0.3.1" + version: "0.3.2" license_type: NOTICE last_upgrade_date { year: 2021 - month: 5 - day: 19 + month: 6 + day: 21 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index 73ad094..a83b104 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -14,15 +14,33 @@ "name": "tokio-test_device_test_tests_macros" }, { + "name": "tokio_device_test_tests__require_full" + }, + { "name": "tokio_device_test_tests_buffered" }, { + "name": "tokio_device_test_tests_io_async_fd" + }, + { "name": "tokio_device_test_tests_io_async_read" }, { + "name": "tokio_device_test_tests_io_chain" + }, + { + "name": "tokio_device_test_tests_io_copy" + }, + { "name": "tokio_device_test_tests_io_copy_bidirectional" }, { + "name": "tokio_device_test_tests_io_driver" + }, + { + "name": "tokio_device_test_tests_io_driver_drop" + }, + { "name": "tokio_device_test_tests_io_lines" }, { @@ -35,9 +53,24 @@ "name": "tokio_device_test_tests_io_read_buf" }, { + "name": "tokio_device_test_tests_io_read_exact" + }, + { + "name": "tokio_device_test_tests_io_read_line" + }, + { "name": "tokio_device_test_tests_io_read_to_end" }, { + "name": "tokio_device_test_tests_io_read_to_string" + }, + { + "name": "tokio_device_test_tests_io_read_until" + }, + { + "name": "tokio_device_test_tests_io_split" + }, + { "name": "tokio_device_test_tests_io_take" }, { @@ -56,12 +89,36 @@ "name": "tokio_device_test_tests_macros_join" }, { + "name": "tokio_device_test_tests_macros_pin" + }, + { + "name": "tokio_device_test_tests_macros_select" + }, + { + "name": "tokio_device_test_tests_macros_test" + }, + { + "name": "tokio_device_test_tests_macros_try_join" + }, + { + "name": "tokio_device_test_tests_net_bind_resource" + }, + { + "name": "tokio_device_test_tests_net_lookup_host" + }, + { "name": "tokio_device_test_tests_no_rt" }, { + "name": "tokio_device_test_tests_process_kill_on_drop" + }, + { "name": "tokio_device_test_tests_rt_basic" }, { + "name": "tokio_device_test_tests_rt_common" + }, + { "name": "tokio_device_test_tests_rt_threaded" }, { @@ -77,15 +134,36 @@ "name": "tokio_device_test_tests_sync_mpsc" }, { + "name": "tokio_device_test_tests_sync_mutex" + }, + { "name": "tokio_device_test_tests_sync_mutex_owned" }, { + "name": "tokio_device_test_tests_sync_notify" + }, + { + "name": "tokio_device_test_tests_sync_oneshot" + }, + { "name": "tokio_device_test_tests_sync_rwlock" }, { + "name": "tokio_device_test_tests_sync_semaphore" + }, + { + "name": "tokio_device_test_tests_sync_semaphore_owned" + }, + { "name": "tokio_device_test_tests_sync_watch" }, { + "name": "tokio_device_test_tests_task_abort" + }, + { + "name": "tokio_device_test_tests_task_blocking" + }, + { "name": "tokio_device_test_tests_task_local" }, { @@ -95,18 +173,39 @@ "name": "tokio_device_test_tests_tcp_accept" }, { + "name": "tokio_device_test_tests_tcp_connect" + }, + { "name": "tokio_device_test_tests_tcp_echo" }, { + "name": "tokio_device_test_tests_tcp_into_split" + }, + { "name": "tokio_device_test_tests_tcp_into_std" }, { + "name": "tokio_device_test_tests_tcp_peek" + }, + { "name": "tokio_device_test_tests_tcp_shutdown" }, { + "name": "tokio_device_test_tests_tcp_socket" + }, + { + "name": "tokio_device_test_tests_tcp_split" + }, + { "name": "tokio_device_test_tests_time_rt" }, { + "name": "tokio_device_test_tests_udp" + }, + { + "name": "tokio_device_test_tests_uds_cred" + }, + { "name": "tokio_device_test_tests_uds_split" } ] @@ -2,7 +2,7 @@ extern crate proc_macro; use proc_macro::TokenStream; use proc_macro2::{Group, TokenStream as TokenStream2, TokenTree}; use quote::quote; -use syn::parse::Parser; +use syn::parse::{Parse, ParseStream, Parser, Result}; use syn::visit_mut::VisitMut; struct Scrub<'a> { @@ -35,6 +35,80 @@ impl<'a> Scrub<'a> { } } +struct Partial<T>(T, TokenStream2); + +impl<T: Parse> Parse for Partial<T> { + fn parse(input: ParseStream) -> Result<Self> { + Ok(Partial(input.parse()?, input.parse()?)) + } +} + +fn visit_token_stream_impl( + visitor: &mut Scrub<'_>, + tokens: TokenStream2, + modified: &mut bool, + out: &mut TokenStream2, +) { + use quote::ToTokens; + use quote::TokenStreamExt; + + let mut tokens = tokens.into_iter().peekable(); + while let Some(tt) = tokens.next() { + match tt { + TokenTree::Ident(i) if i == "yield" => { + let stream = std::iter::once(TokenTree::Ident(i)).chain(tokens).collect(); + match syn::parse2(stream) { + Ok(Partial(yield_expr, rest)) => { + let mut expr = syn::Expr::Yield(yield_expr); + visitor.visit_expr_mut(&mut expr); + expr.to_tokens(out); + *modified = true; + tokens = rest.into_iter().peekable(); + } + Err(e) => { + out.append_all(&mut e.to_compile_error().into_iter()); + *modified = true; + return; + } + } + } + TokenTree::Ident(i) if i == "stream" || i == "try_stream" => { + out.append(TokenTree::Ident(i)); + match tokens.peek() { + Some(TokenTree::Punct(p)) if p.as_char() == '!' => { + out.extend(tokens.next()); // ! + if let Some(TokenTree::Group(_)) = tokens.peek() { + out.extend(tokens.next()); // { .. } or [ .. ] or ( .. ) + } + } + _ => {} + } + } + TokenTree::Group(group) => { + let mut content = group.stream(); + *modified |= visitor.visit_token_stream(&mut content); + let mut new = Group::new(group.delimiter(), content); + new.set_span(group.span()); + out.append(new); + } + other => out.append(other), + } + } +} + +impl Scrub<'_> { + fn visit_token_stream(&mut self, tokens: &mut TokenStream2) -> bool { + let (mut out, mut modified) = (TokenStream2::new(), false); + visit_token_stream_impl(self, tokens.clone(), &mut modified, &mut out); + + if modified { + *tokens = out; + } + + modified + } +} + impl VisitMut for Scrub<'_> { fn visit_expr_mut(&mut self, i: &mut syn::Expr) { match i { @@ -110,8 +184,20 @@ impl VisitMut for Scrub<'_> { } } - fn visit_item_mut(&mut self, _: &mut syn::Item) { - // Don't transform inner items. + fn visit_macro_mut(&mut self, mac: &mut syn::Macro) { + let mac_ident = mac.path.segments.last().map(|p| &p.ident); + if mac_ident.map_or(false, |i| i == "stream" || i == "try_stream") { + return; + } + + self.visit_token_stream(&mut mac.tokens); + } + + fn visit_item_mut(&mut self, i: &mut syn::Item) { + // Recurse into macros but otherwise don't transform inner items. + if let syn::Item::Macro(i) = i { + self.visit_macro_mut(&mut i.mac); + } } } |