diff options
author | Matthew Maurer <mmaurer@google.com> | 2023-05-26 23:48:39 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-05-26 23:48:39 +0000 |
commit | 472328dc82aaecbf4eb2cbf4114d2d5d4a91181c (patch) | |
tree | d76962be936e87660661fc427c7a9a293da114dd | |
parent | 39ff3ac1e52b2d26b53afc87f5c72180c5bd829f (diff) | |
parent | 2787802ac4f3d9971b29c3615a81be6aaa359d80 (diff) | |
download | tokio-macros-472328dc82aaecbf4eb2cbf4114d2d5d4a91181c.tar.gz |
Upgrade tokio-macros to 2.0.0 am: 2a70bbf57d am: b9a4894029 am: 2787802ac4
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/tokio-macros/+/2518225
Change-Id: I9cedf5e08a39653ac38fcbc27427353c7512a1e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 15 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | src/entry.rs | 70 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/select.rs | 11 |
10 files changed, 74 insertions, 57 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 6e0797d..8ef4c84 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "993a60b7c79b6fbdad872c6a173c2e6fe42b117f" + "sha1": "614fe357fc4a91bc6d1c904fbbfe3c5959f690f6" }, "path_in_vcs": "tokio-macros" }
\ No newline at end of file @@ -22,7 +22,7 @@ rust_proc_macro { name: "libtokio_macros", crate_name: "tokio_macros", cargo_env_compat: true, - cargo_pkg_version: "1.8.2", + cargo_pkg_version: "2.0.0", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d52e7..2acf402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# 2.0.0 (March 24th, 2023) + +This major release updates the dependency on the syn crate to 2.0.0, and +increases the MSRV to 1.56. + +As part of this release, we are adopting a policy of depending on a specific minor +release of tokio-macros. This prevents Tokio from being able to pull in many different +versions of tokio-macros. + +- macros: update `syn` ([#5572]) +- macros: accept path as crate rename ([#5557]) + +[#5572]: https://github.com/tokio-rs/tokio/pull/5572 +[#5557]: https://github.com/tokio-rs/tokio/pull/5557 + # 1.8.2 (November 30th, 2022) - fix a regression introduced in 1.8.1 ([#5244]) @@ -11,9 +11,9 @@ [package] edition = "2018" -rust-version = "1.49" +rust-version = "1.56" name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" authors = ["Tokio Contributors <team@tokio.rs>"] description = """ Tokio's proc macros. @@ -37,7 +37,7 @@ version = "1.0.7" version = "1" [dependencies.syn] -version = "1.0.56" +version = "2.0" features = ["full"] [dev-dependencies.tokio] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index ea536a8..291da3c 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -4,9 +4,9 @@ name = "tokio-macros" # - Remove path dependencies # - Update CHANGELOG.md. # - Create "tokio-macros-1.x.y" git tag. -version = "1.8.2" +version = "2.0.0" edition = "2018" -rust-version = "1.49" +rust-version = "1.56" authors = ["Tokio Contributors <team@tokio.rs>"] license = "MIT" repository = "https://github.com/tokio-rs/tokio" @@ -24,7 +24,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.7" quote = "1" -syn = { version = "1.0.56", features = ["full"] } +syn = { version = "2.0", features = ["full"] } [dev-dependencies] tokio = { version = "1.0.0", path = "../tokio", features = ["full"] } @@ -1,4 +1,4 @@ -Copyright (c) 2022 Tokio Contributors +Copyright (c) 2023 Tokio Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/tokio-macros/tokio-macros-1.8.2.crate" + value: "https://static.crates.io/crates/tokio-macros/tokio-macros-2.0.0.crate" } - version: "1.8.2" + version: "2.0.0" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 12 + year: 2023 + month: 4 + day: 3 } } diff --git a/src/entry.rs b/src/entry.rs index 6460e70..3b124cf 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -1,10 +1,10 @@ use proc_macro::TokenStream; -use proc_macro2::{Ident, Span}; +use proc_macro2::Span; use quote::{quote, quote_spanned, ToTokens}; -use syn::parse::Parser; +use syn::{parse::Parser, Ident, Path}; // syn::AttributeArgs does not implement syn::Parse -type AttributeArgs = syn::punctuated::Punctuated<syn::NestedMeta, syn::Token![,]>; +type AttributeArgs = syn::punctuated::Punctuated<syn::Meta, syn::Token![,]>; #[derive(Clone, Copy, PartialEq)] enum RuntimeFlavor { @@ -29,7 +29,7 @@ struct FinalConfig { flavor: RuntimeFlavor, worker_threads: Option<usize>, start_paused: Option<bool>, - crate_name: Option<String>, + crate_name: Option<Path>, } /// Config used in case of the attribute not being able to build a valid config @@ -47,7 +47,7 @@ struct Configuration { worker_threads: Option<(usize, Span)>, start_paused: Option<(bool, Span)>, is_test: bool, - crate_name: Option<String>, + crate_name: Option<Path>, } impl Configuration { @@ -112,8 +112,8 @@ impl Configuration { if self.crate_name.is_some() { return Err(syn::Error::new(span, "`crate` set multiple times.")); } - let name_ident = parse_ident(name, span, "crate")?; - self.crate_name = Some(name_ident.to_string()); + let name_path = parse_path(name, span, "crate")?; + self.crate_name = Some(name_path); Ok(()) } @@ -199,23 +199,22 @@ fn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::E } } -fn parse_ident(lit: syn::Lit, span: Span, field: &str) -> Result<Ident, syn::Error> { +fn parse_path(lit: syn::Lit, span: Span, field: &str) -> Result<Path, syn::Error> { match lit { syn::Lit::Str(s) => { let err = syn::Error::new( span, format!( - "Failed to parse value of `{}` as ident: \"{}\"", + "Failed to parse value of `{}` as path: \"{}\"", field, s.value() ), ); - let path = s.parse::<syn::Path>().map_err(|_| err.clone())?; - path.get_ident().cloned().ok_or(err) + s.parse::<syn::Path>().map_err(|_| err.clone()) } _ => Err(syn::Error::new( span, - format!("Failed to parse value of `{}` as ident.", field), + format!("Failed to parse value of `{}` as path.", field), )), } } @@ -246,7 +245,7 @@ fn build_config( for arg in args { match arg { - syn::NestedMeta::Meta(syn::Meta::NameValue(namevalue)) => { + syn::Meta::NameValue(namevalue) => { let ident = namevalue .path .get_ident() @@ -255,34 +254,26 @@ fn build_config( })? .to_string() .to_lowercase(); + let lit = match &namevalue.value { + syn::Expr::Lit(syn::ExprLit { lit, .. }) => lit, + expr => return Err(syn::Error::new_spanned(expr, "Must be a literal")), + }; match ident.as_str() { "worker_threads" => { - config.set_worker_threads( - namevalue.lit.clone(), - syn::spanned::Spanned::span(&namevalue.lit), - )?; + config.set_worker_threads(lit.clone(), syn::spanned::Spanned::span(lit))?; } "flavor" => { - config.set_flavor( - namevalue.lit.clone(), - syn::spanned::Spanned::span(&namevalue.lit), - )?; + config.set_flavor(lit.clone(), syn::spanned::Spanned::span(lit))?; } "start_paused" => { - config.set_start_paused( - namevalue.lit.clone(), - syn::spanned::Spanned::span(&namevalue.lit), - )?; + config.set_start_paused(lit.clone(), syn::spanned::Spanned::span(lit))?; } "core_threads" => { let msg = "Attribute `core_threads` is renamed to `worker_threads`"; return Err(syn::Error::new_spanned(namevalue, msg)); } "crate" => { - config.set_crate_name( - namevalue.lit.clone(), - syn::spanned::Spanned::span(&namevalue.lit), - )?; + config.set_crate_name(lit.clone(), syn::spanned::Spanned::span(lit))?; } name => { let msg = format!( @@ -293,7 +284,7 @@ fn build_config( } } } - syn::NestedMeta::Meta(syn::Meta::Path(path)) => { + syn::Meta::Path(path) => { let name = path .get_ident() .ok_or_else(|| syn::Error::new_spanned(&path, "Must have specified ident"))? @@ -354,16 +345,17 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To (start, end) }; - let crate_name = config.crate_name.as_deref().unwrap_or("tokio"); - - let crate_ident = Ident::new(crate_name, last_stmt_start_span); + let crate_path = config + .crate_name + .map(ToTokens::into_token_stream) + .unwrap_or_else(|| Ident::new("tokio", last_stmt_start_span).into_token_stream()); let mut rt = match config.flavor { RuntimeFlavor::CurrentThread => quote_spanned! {last_stmt_start_span=> - #crate_ident::runtime::Builder::new_current_thread() + #crate_path::runtime::Builder::new_current_thread() }, RuntimeFlavor::Threaded => quote_spanned! {last_stmt_start_span=> - #crate_ident::runtime::Builder::new_multi_thread() + #crate_path::runtime::Builder::new_multi_thread() }, }; if let Some(v) = config.worker_threads { @@ -414,7 +406,7 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To }; quote! { let body = async #body; - #crate_ident::pin!(body); + #crate_path::pin!(body); let body: ::std::pin::Pin<&mut dyn ::std::future::Future<Output = #output_type>> = body; } } else { @@ -478,7 +470,11 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) Ok(it) => it, Err(e) => return token_stream_with_error(item, e), }; - let config = if let Some(attr) = input.attrs.iter().find(|attr| attr.path.is_ident("test")) { + let config = if let Some(attr) = input + .attrs + .iter() + .find(|attr| attr.meta.path().is_ident("test")) + { let msg = "second test attribute is supplied"; Err(syn::Error::new_spanned(attr, msg)) } else { @@ -39,6 +39,13 @@ use proc_macro::TokenStream; /// function is called often, it is preferable to create the runtime using the /// runtime builder so the runtime can be reused across calls. /// +/// # Non-worker async function +/// +/// Note that the async function marked with this macro does not run as a +/// worker. The expectation is that other tasks are spawned by the function here. +/// Awaiting on other futures from the function provided here will not +/// perform as fast as those spawned as workers. +/// /// # Multi-threaded runtime /// /// To use the multi-threaded runtime, the macro can be configured using diff --git a/src/select.rs b/src/select.rs index 23e280a..dd491f8 100644 --- a/src/select.rs +++ b/src/select.rs @@ -1,7 +1,7 @@ use proc_macro::{TokenStream, TokenTree}; use proc_macro2::Span; use quote::quote; -use syn::Ident; +use syn::{parse::Parser, Ident}; pub(crate) fn declare_output_enum(input: TokenStream) -> TokenStream { // passed in is: `(_ _ _)` with one `_` per branch @@ -46,7 +46,7 @@ pub(crate) fn clean_pattern_macro(input: TokenStream) -> TokenStream { // If this isn't a pattern, we return the token stream as-is. The select! // macro is using it in a location requiring a pattern, so an error will be // emitted there. - let mut input: syn::Pat = match syn::parse(input.clone()) { + let mut input: syn::Pat = match syn::Pat::parse_single.parse(input.clone()) { Ok(it) => it, Err(_) => return input, }; @@ -58,7 +58,6 @@ pub(crate) fn clean_pattern_macro(input: TokenStream) -> TokenStream { // Removes any occurrences of ref or mut in the provided pattern. fn clean_pattern(pat: &mut syn::Pat) { match pat { - syn::Pat::Box(_box) => {} syn::Pat::Lit(_literal) => {} syn::Pat::Macro(_macro) => {} syn::Pat::Path(_path) => {} @@ -94,16 +93,16 @@ fn clean_pattern(pat: &mut syn::Pat) { } } syn::Pat::TupleStruct(tuple) => { - for elem in tuple.pat.elems.iter_mut() { + for elem in tuple.elems.iter_mut() { clean_pattern(elem); } } syn::Pat::Reference(reference) => { reference.mutability = None; - clean_pattern(&mut *reference.pat); + clean_pattern(&mut reference.pat); } syn::Pat::Type(type_pat) => { - clean_pattern(&mut *type_pat.pat); + clean_pattern(&mut type_pat.pat); } _ => {} } |