aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-05-27 00:57:45 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-05-27 00:57:45 +0000
commite933ac5e4478575f6b468d52778d067270f37932 (patch)
treed76962be936e87660661fc427c7a9a293da114dd
parent130725192a3aa001fc1735fb07cdb2291c4727ec (diff)
parent472328dc82aaecbf4eb2cbf4114d2d5d4a91181c (diff)
downloadtokio-macros-e933ac5e4478575f6b468d52778d067270f37932.tar.gz
Upgrade tokio-macros to 2.0.0 am: 2a70bbf57d am: b9a4894029 am: 2787802ac4 am: 472328dc82
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/tokio-macros/+/2518225 Change-Id: I9ef8f508e6627334fb7ae90d85f76d81ab060453 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp2
-rw-r--r--CHANGELOG.md15
-rw-r--r--Cargo.toml6
-rw-r--r--Cargo.toml.orig6
-rw-r--r--LICENSE2
-rw-r--r--METADATA10
-rw-r--r--src/entry.rs70
-rw-r--r--src/lib.rs7
-rw-r--r--src/select.rs11
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
diff --git a/Android.bp b/Android.bp
index 2f4eafc..7321a78 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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])
diff --git a/Cargo.toml b/Cargo.toml
index 04bfa41..0dd94fb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"] }
diff --git a/LICENSE b/LICENSE
index a3753c0..12d1037 100644
--- a/LICENSE
+++ b/LICENSE
@@ -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
diff --git a/METADATA b/METADATA
index e03bdf5..118d743 100644
--- a/METADATA
+++ b/METADATA
@@ -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 {
diff --git a/src/lib.rs b/src/lib.rs
index 34041af..11bbbae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);
}
_ => {}
}