From 75bf7197499eb2255e3019be5c1cad4676cd6dc7 Mon Sep 17 00:00:00 2001 From: James Farrell Date: Wed, 16 Aug 2023 19:13:20 +0000 Subject: Upgrade async-trait to 0.1.73 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/async-trait For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: I6ca2d54e5684edb52f2cf797d4a7ddb1727a3b02 Bug: 295883071 --- .cargo_vcs_info.json | 2 +- .clippy.toml | 1 - .github/workflows/ci.yml | 13 +++++++++++++ Android.bp | 4 ++-- Cargo.toml | 21 +++++++++++---------- Cargo.toml.orig | 21 +++++++++++---------- METADATA | 10 +++++----- src/expand.rs | 32 ++++++++++++++++++++------------ src/lib.rs | 13 +++++++------ src/receiver.rs | 1 - src/verbatim.rs | 34 ++++++++++++++++++++++++++++++++++ tests/test.rs | 9 +++++---- tests/ui/bare-trait-object.stderr | 11 ++--------- tests/ui/consider-restricting.stderr | 6 ++++-- tests/ui/send-not-implemented.stderr | 14 ++++++++------ 15 files changed, 123 insertions(+), 69 deletions(-) delete mode 100644 .clippy.toml create mode 100644 src/verbatim.rs diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 85b96d9..6c6616b 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "f8a86505696c2206676cf2355dce1a6a27d28005" + "sha1": "f07c8568702978c72d0c282f719a4649065ac517" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/.clippy.toml b/.clippy.toml deleted file mode 100644 index 0d369b5..0000000 --- a/.clippy.toml +++ /dev/null @@ -1 +0,0 @@ -msrv = "1.56.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ac696a..942dd36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,18 @@ jobs: if: matrix.rust == 'nightly' - run: cargo test + minimal: + name: Minimal versions + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - run: cargo generate-lockfile -Z minimal-versions + - run: cargo check --locked + clippy: name: Clippy runs-on: ubuntu-latest @@ -58,6 +70,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@miri + - run: cargo miri setup - run: cargo miri test env: MIRIFLAGS: -Zmiri-strict-provenance diff --git a/Android.bp b/Android.bp index 0ded84e..29d4efd 100644 --- a/Android.bp +++ b/Android.bp @@ -41,9 +41,9 @@ rust_proc_macro { name: "libasync_trait", crate_name: "async_trait", cargo_env_compat: true, - cargo_pkg_version: "0.1.67", + cargo_pkg_version: "0.1.73", srcs: ["src/lib.rs"], - edition: "2018", + edition: "2021", rustlibs: [ "libproc_macro2", "libquote", diff --git a/Cargo.toml b/Cargo.toml index 0e91d4a..b8058ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,10 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" rust-version = "1.56" name = "async-trait" -version = "0.1.67" +version = "0.1.73" authors = ["David Tolnay "] description = "Type erasure for async trait methods" documentation = "https://docs.rs/async-trait" @@ -27,36 +27,37 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/async-trait" [package.metadata.docs.rs] +rustdoc-args = ["--generate-link-to-definition"] targets = ["x86_64-unknown-linux-gnu"] [lib] proc-macro = true [dependencies.proc-macro2] -version = "1.0" +version = "1.0.63" [dependencies.quote] -version = "1.0" +version = "1.0.29" [dependencies.syn] -version = "2.0" +version = "2.0.23" features = [ "full", "visit-mut", ] [dev-dependencies.futures] -version = "0.3" +version = "0.3.28" [dev-dependencies.rustversion] -version = "1.0" +version = "1.0.13" [dev-dependencies.tracing] -version = "0.1.14" +version = "0.1.37" [dev-dependencies.tracing-attributes] -version = "0.1.14" +version = "0.1.26" [dev-dependencies.trybuild] -version = "1.0.49" +version = "1.0.81" features = ["diff"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index d99bf18..3c8f287 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,11 +1,11 @@ [package] name = "async-trait" -version = "0.1.67" +version = "0.1.73" authors = ["David Tolnay "] categories = ["asynchronous", "no-std"] description = "Type erasure for async trait methods" documentation = "https://docs.rs/async-trait" -edition = "2018" +edition = "2021" keywords = ["async"] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/async-trait" @@ -15,16 +15,17 @@ rust-version = "1.56" proc-macro = true [dependencies] -proc-macro2 = "1.0" -quote = "1.0" -syn = { version = "2.0", features = ["full", "visit-mut"] } +proc-macro2 = "1.0.63" +quote = "1.0.29" +syn = { version = "2.0.23", features = ["full", "visit-mut"] } [dev-dependencies] -futures = "0.3" -rustversion = "1.0" -tracing = "0.1.14" -tracing-attributes = "0.1.14" -trybuild = { version = "1.0.49", features = ["diff"] } +futures = "0.3.28" +rustversion = "1.0.13" +tracing = "0.1.37" +tracing-attributes = "0.1.26" +trybuild = { version = "1.0.81", features = ["diff"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = ["--generate-link-to-definition"] diff --git a/METADATA b/METADATA index e6e568a..403a480 100644 --- a/METADATA +++ b/METADATA @@ -1,6 +1,6 @@ # This project was upgraded with external_updater. # Usage: tools/external_updater/updater.sh update rust/crates/async-trait -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "async-trait" description: "Type erasure for async trait methods" @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/async-trait/async-trait-0.1.67.crate" + value: "https://static.crates.io/crates/async-trait/async-trait-0.1.73.crate" } - version: "0.1.67" + version: "0.1.73" license_type: NOTICE last_upgrade_date { year: 2023 - month: 3 - day: 23 + month: 8 + day: 16 } } diff --git a/src/expand.rs b/src/expand.rs index 362ba78..2a8b3c2 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -2,6 +2,7 @@ use crate::bound::{has_bound, InferredBound, Supertraits}; use crate::lifetime::{AddLifetimeToImplTrait, CollectLifetimes}; use crate::parse::Item; use crate::receiver::{has_self_in_block, has_self_in_sig, mut_pat, ReplaceSelf}; +use crate::verbatim::VerbatimFn; use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote, quote_spanned, ToTokens}; use std::collections::BTreeSet as Set; @@ -11,7 +12,7 @@ use syn::visit_mut::{self, VisitMut}; use syn::{ parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericArgument, GenericParam, Generics, Ident, ImplItem, Lifetime, LifetimeParam, Pat, PatIdent, PathArguments, Receiver, - ReturnType, Signature, Stmt, Token, TraitItem, Type, TypePath, WhereClause, + ReturnType, Signature, Token, TraitItem, Type, TypePath, WhereClause, }; impl ToTokens for Item { @@ -94,15 +95,27 @@ pub fn expand(input: &mut Item, is_local: bool) { associated_type_impl_traits: &associated_type_impl_traits, }; for inner in &mut input.items { - if let ImplItem::Fn(method) = inner { - let sig = &mut method.sig; - if sig.asyncness.is_some() { + match inner { + ImplItem::Fn(method) if method.sig.asyncness.is_some() => { + let sig = &mut method.sig; let block = &mut method.block; let has_self = has_self_in_sig(sig) || has_self_in_block(block); transform_block(context, sig, block); transform_sig(context, sig, has_self, false, is_local); method.attrs.push(lint_suppress_with_body()); } + ImplItem::Verbatim(tokens) => { + let mut method = match syn::parse2::(tokens.clone()) { + Ok(method) if method.sig.asyncness.is_some() => method, + _ => continue, + }; + let sig = &mut method.sig; + let has_self = has_self_in_sig(sig); + transform_sig(context, sig, has_self, false, is_local); + method.attrs.push(lint_suppress_with_body()); + *tokens = quote!(#method); + } + _ => {} } } } @@ -113,6 +126,7 @@ fn lint_suppress_with_body() -> Attribute { parse_quote! { #[allow( clippy::async_yields_async, + clippy::diverging_sub_expression, clippy::let_unit_value, clippy::no_effect_underscore_binding, clippy::shadow_same, @@ -161,7 +175,7 @@ fn transform_sig( }; let mut lifetimes = CollectLifetimes::new(); - for arg in sig.inputs.iter_mut() { + for arg in &mut sig.inputs { match arg { FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg), FnArg::Typed(arg) => lifetimes.visit_type_mut(&mut arg.ty), @@ -329,12 +343,6 @@ fn transform_sig( // ___ret // }) fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) { - if let Some(Stmt::Item(syn::Item::Verbatim(item))) = block.stmts.first() { - if block.stmts.len() == 1 && item.to_string() == ";" { - return; - } - } - let mut self_span = None; let decls = sig .inputs @@ -398,7 +406,7 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) { let let_ret = match &mut sig.output { ReturnType::Default => quote_spanned! {block.brace_token.span=> #(#decls)* - let _: () = { #(#stmts)* }; + let () = { #(#stmts)* }; }, ReturnType::Type(_, ret) => { if contains_associated_type_impl_trait(context, ret) { diff --git a/src/lib.rs b/src/lib.rs index ec893f6..e35dd03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,7 @@ //! # Explanation //! //! Async fns get transformed into methods that return `Pin>` and delegate to a private async freestanding function. +//! Send + 'async_trait>>` and delegate to a private async freestanding function. //! //! For example the `impl Advertisement for AutoplayingVideo` above would be //! expanded as: @@ -126,11 +126,11 @@ //! ``` //! # const IGNORE: &str = stringify! { //! impl Advertisement for AutoplayingVideo { -//! fn run<'async>( -//! &'async self, -//! ) -> Pin + Send + 'async>> +//! fn run<'async_trait>( +//! &'async_trait self, +//! ) -> Pin + Send + 'async_trait>> //! where -//! Self: Sync + 'async, +//! Self: Sync + 'async_trait, //! { //! async fn run(_self: &AutoplayingVideo) { //! /* the original method body */ @@ -303,7 +303,7 @@ //! let object = &value as &dyn ObjectSafe; //! ``` -#![doc(html_root_url = "https://docs.rs/async-trait/0.1.67")] +#![doc(html_root_url = "https://docs.rs/async-trait/0.1.73")] #![allow( clippy::default_trait_access, clippy::doc_markdown, @@ -325,6 +325,7 @@ mod expand; mod lifetime; mod parse; mod receiver; +mod verbatim; use crate::args::Args; use crate::expand::expand; diff --git a/src/receiver.rs b/src/receiver.rs index 6de5090..f5791bf 100644 --- a/src/receiver.rs +++ b/src/receiver.rs @@ -1,5 +1,4 @@ use proc_macro2::{Group, Span, TokenStream, TokenTree}; -use std::iter::FromIterator; use syn::visit_mut::{self, VisitMut}; use syn::{ Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, Path, Receiver, Signature, Token, TypePath, diff --git a/src/verbatim.rs b/src/verbatim.rs new file mode 100644 index 0000000..d064f6e --- /dev/null +++ b/src/verbatim.rs @@ -0,0 +1,34 @@ +use proc_macro2::TokenStream; +use quote::{ToTokens, TokenStreamExt}; +use syn::parse::{Parse, ParseStream, Result}; +use syn::{Attribute, Signature, Token, Visibility}; + +pub struct VerbatimFn { + pub attrs: Vec, + pub vis: Visibility, + pub defaultness: Option, + pub sig: Signature, + pub semi_token: Token![;], +} + +impl Parse for VerbatimFn { + fn parse(input: ParseStream) -> Result { + Ok(VerbatimFn { + attrs: input.call(Attribute::parse_outer)?, + vis: input.parse()?, + defaultness: input.parse()?, + sig: input.parse()?, + semi_token: input.parse()?, + }) + } +} + +impl ToTokens for VerbatimFn { + fn to_tokens(&self, tokens: &mut TokenStream) { + tokens.append_all(&self.attrs); + self.vis.to_tokens(tokens); + self.defaultness.to_tokens(tokens); + self.sig.to_tokens(tokens); + self.semi_token.to_tokens(tokens); + } +} diff --git a/tests/test.rs b/tests/test.rs index f36618f..650959c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,6 +1,6 @@ #![cfg_attr( async_trait_nightly_testing, - feature(min_specialization, type_alias_impl_trait) + feature(impl_trait_in_assoc_type, min_specialization) )] #![deny(rust_2021_compatibility)] #![allow( @@ -9,6 +9,7 @@ clippy::missing_panics_doc, clippy::missing_safety_doc, clippy::needless_return, + clippy::non_minimal_cfg, clippy::trivially_copy_pass_by_ref, clippy::unused_async )] @@ -872,7 +873,7 @@ pub mod issue89 { } #[async_trait] - impl Trait for Send + Sync { + impl Trait for dyn Send + Sync { async fn f(&self) {} } @@ -946,7 +947,7 @@ pub mod issue92 { mac!(let _ = ::associated1();); // trait items - mac!(let _: ::Associated2;); + mac!(let (): ::Associated2;); mac!(Self::ASSOCIATED2;); mac!(::ASSOCIATED2;); mac!(::ASSOCIATED2;); @@ -1354,7 +1355,7 @@ pub mod issue161 { impl Trait for MyStruct { async fn f(self: Arc) { futures::select! { - _ = async { + () = async { println!("{}", self.0); }.fuse() => {} } diff --git a/tests/ui/bare-trait-object.stderr b/tests/ui/bare-trait-object.stderr index 50b2048..7ff6af1 100644 --- a/tests/ui/bare-trait-object.stderr +++ b/tests/ui/bare-trait-object.stderr @@ -1,17 +1,10 @@ -error: trait objects without an explicit `dyn` are deprecated +error[E0782]: trait objects must include the `dyn` keyword --> tests/ui/bare-trait-object.rs:11:16 | 11 | impl Trait for Send + Sync { | ^^^^^^^^^^^ | - = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! - = note: for more information, see -note: the lint level is defined here - --> tests/ui/bare-trait-object.rs:1:9 - | -1 | #![deny(bare_trait_objects)] - | ^^^^^^^^^^^^^^^^^^ -help: use `dyn` +help: add `dyn` keyword before this trait | 11 | impl Trait for dyn Send + Sync { | +++ diff --git a/tests/ui/consider-restricting.stderr b/tests/ui/consider-restricting.stderr index 62ff894..5f7fd00 100644 --- a/tests/ui/consider-restricting.stderr +++ b/tests/ui/consider-restricting.stderr @@ -4,12 +4,13 @@ error: future cannot be sent between threads safely 16 | async fn publish(&self, url: T) {} | ^^ future created by async block is not `Send` | + = note: consider using `std::sync::Arc`; for more information visit note: captured value is not `Send` --> tests/ui/consider-restricting.rs:16:41 | 16 | async fn publish(&self, url: T) {} | ^^^ has type `T` which is not `Send` - = note: required for the cast from `[async block@$DIR/tests/ui/consider-restricting.rs:16:49: 16:51]` to the object type `dyn Future + Send` + = note: required for the cast from `Pin>` to `Pin + Send + 'async_trait)>>` help: consider further restricting this bound | 16 | async fn publish(&self, url: T) {} @@ -21,12 +22,13 @@ error: future cannot be sent between threads safely 23 | async fn publish(&self, url: T) {} | ^^ future created by async block is not `Send` | + = note: consider using `std::sync::Arc`; for more information visit note: captured value is not `Send` --> tests/ui/consider-restricting.rs:23:32 | 23 | async fn publish(&self, url: T) {} | ^^^ has type `T` which is not `Send` - = note: required for the cast from `[async block@$DIR/tests/ui/consider-restricting.rs:23:40: 23:42]` to the object type `dyn Future + Send` + = note: required for the cast from `Pin>` to `Pin + Send + 'async_trait)>>` help: consider further restricting this bound | 23 | async fn publish(&self, url: T) {} diff --git a/tests/ui/send-not-implemented.stderr b/tests/ui/send-not-implemented.stderr index d68fc43..b8aedfd 100644 --- a/tests/ui/send-not-implemented.stderr +++ b/tests/ui/send-not-implemented.stderr @@ -10,16 +10,17 @@ error: future cannot be sent between threads safely | |_____^ future created by async block is not `Send` | = help: within `[async block@$DIR/tests/ui/send-not-implemented.rs:8:26: 12:6]`, the trait `Send` is not implemented for `MutexGuard<'_, ()>` + = note: consider using `std::sync::Arc>`; for more information visit note: future is not `Send` as this value is used across an await - --> tests/ui/send-not-implemented.rs:11:12 + --> tests/ui/send-not-implemented.rs:11:13 | 10 | let _guard = mutex.lock().unwrap(); | ------ has type `MutexGuard<'_, ()>` which is not `Send` 11 | f().await; - | ^^^^^^ await occurs here, with `_guard` maybe used later + | ^^^^^ await occurs here, with `_guard` maybe used later 12 | } | - `_guard` is later dropped here - = note: required for the cast from `[async block@$DIR/tests/ui/send-not-implemented.rs:8:26: 12:6]` to the object type `dyn Future + Send` + = note: required for the cast from `Pin>` to `Pin + Send + 'async_trait)>>` error: future cannot be sent between threads safely --> tests/ui/send-not-implemented.rs:14:38 @@ -34,14 +35,15 @@ error: future cannot be sent between threads safely | |_____^ future created by async block is not `Send` | = help: within `[async block@$DIR/tests/ui/send-not-implemented.rs:14:38: 19:6]`, the trait `Send` is not implemented for `MutexGuard<'_, ()>` + = note: consider using `std::sync::Arc>`; for more information visit note: future is not `Send` as this value is used across an await - --> tests/ui/send-not-implemented.rs:17:12 + --> tests/ui/send-not-implemented.rs:17:13 | 16 | let _guard = mutex.lock().unwrap(); | ------ has type `MutexGuard<'_, ()>` which is not `Send` 17 | f().await; - | ^^^^^^ await occurs here, with `_guard` maybe used later + | ^^^^^ await occurs here, with `_guard` maybe used later 18 | true 19 | } | - `_guard` is later dropped here - = note: required for the cast from `[async block@$DIR/tests/ui/send-not-implemented.rs:14:38: 19:6]` to the object type `dyn Future + Send` + = note: required for the cast from `Pin>` to `Pin + Send + 'async_trait)>>` -- cgit v1.2.3