aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2023-02-01 12:38:45 +0100
committerJeff Vander Stoep <jeffv@google.com>2023-02-01 12:38:45 +0100
commitbe0b70ddd642d63bfeb09673d0c5817a09cad2b1 (patch)
tree50b932b65878ae2c96b9152dcaebec0329d2dad9
parent3b055f3f26329de276763ee169f1ff745b5185fb (diff)
downloadasync-trait-be0b70ddd642d63bfeb09673d0c5817a09cad2b1.tar.gz
Upgrade async-trait to 0.1.64
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 Test: TreeHugger Change-Id: I515624291c092977ad527fcab44269152a83413d
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml9
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--LICENSE-APACHE25
-rw-r--r--METADATA10
-rw-r--r--README.md2
-rw-r--r--build.rs2
-rw-r--r--src/expand.rs47
-rw-r--r--src/lifetime.rs19
-rw-r--r--tests/test.rs123
-rw-r--r--tests/ui/lifetime-defined-here.rs23
-rw-r--r--tests/ui/lifetime-defined-here.stderr29
14 files changed, 242 insertions, 55 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index ed1a319..4b97a9e 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "c1fba00e2ec717d22272d0922c6062e25181bff8"
+ "sha1": "6a13fce88235ebd11c0c67f419a3153dcd349eb9"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 531e97e..9443750 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,8 +12,13 @@ env:
RUSTFLAGS: -Dwarnings
jobs:
+ pre_ci:
+ uses: dtolnay/.github/.github/workflows/pre_ci.yml@master
+
test:
name: Rust ${{matrix.rust}}
+ needs: pre_ci
+ if: needs.pre_ci.outputs.continue
runs-on: ubuntu-latest
strategy:
fail-fast: false
@@ -34,6 +39,8 @@ jobs:
msrv:
name: Rust 1.39.0
+ needs: pre_ci
+ if: needs.pre_ci.outputs.continue
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
@@ -53,6 +60,8 @@ jobs:
miri:
name: Miri
+ needs: pre_ci
+ if: needs.pre_ci.outputs.continue
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
diff --git a/Android.bp b/Android.bp
index 4fcaa58..e9ff15b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -41,7 +41,7 @@ rust_proc_macro {
name: "libasync_trait",
crate_name: "async_trait",
cargo_env_compat: true,
- cargo_pkg_version: "0.1.59",
+ cargo_pkg_version: "0.1.64",
srcs: ["src/lib.rs"],
edition: "2018",
rustlibs: [
diff --git a/Cargo.toml b/Cargo.toml
index 9af1d7a..5a6efbe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.39"
name = "async-trait"
-version = "0.1.59"
+version = "0.1.64"
authors = ["David Tolnay <dtolnay@gmail.com>"]
description = "Type erasure for async trait methods"
documentation = "https://docs.rs/async-trait"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 090eef9..2dd4171 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "async-trait"
-version = "0.1.59"
+version = "0.1.64"
authors = ["David Tolnay <dtolnay@gmail.com>"]
categories = ["asynchronous", "no-std"]
description = "Type erasure for async trait methods"
diff --git a/LICENSE-APACHE b/LICENSE-APACHE
index 16fe87b..1b5ec8b 100644
--- a/LICENSE-APACHE
+++ b/LICENSE-APACHE
@@ -174,28 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
-
-APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
-Copyright [yyyy] [name of copyright owner]
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
diff --git a/METADATA b/METADATA
index d8eed72..0445905 100644
--- a/METADATA
+++ b/METADATA
@@ -11,13 +11,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/async-trait/async-trait-0.1.59.crate"
+ value: "https://static.crates.io/crates/async-trait/async-trait-0.1.64.crate"
}
- version: "0.1.59"
+ version: "0.1.64"
license_type: NOTICE
last_upgrade_date {
- year: 2022
- month: 12
- day: 6
+ year: 2023
+ month: 2
+ day: 1
}
}
diff --git a/README.md b/README.md
index 6ff8989..39e368b 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Async trait methods
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/async--trait-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/async-trait)
[<img alt="crates.io" src="https://img.shields.io/crates/v/async-trait.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/async-trait)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-async--trait-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/async-trait)
-[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/async-trait/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/async-trait/actions?query=branch%3Amaster)
+[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/async-trait/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/async-trait/actions?query=branch%3Amaster)
The initial round of stabilizations for the async/await language feature in Rust
1.39 did not include support for async fn in traits. Trying to include an async
diff --git a/build.rs b/build.rs
index fa2fe1c..d7f6b15 100644
--- a/build.rs
+++ b/build.rs
@@ -3,6 +3,8 @@ use std::process::Command;
use std::str;
fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
+
let compiler = match rustc_minor_version() {
Some(compiler) => compiler,
None => return,
diff --git a/src/expand.rs b/src/expand.rs
index 53918cb..88338db 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -80,7 +80,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
}
}
Item::Impl(input) => {
- let mut lifetimes = CollectLifetimes::new("'impl", input.impl_token.span);
+ let mut lifetimes = CollectLifetimes::new("'impl");
lifetimes.visit_type_mut(&mut *input.self_ty);
lifetimes.visit_path_mut(&mut input.trait_.as_mut().unwrap().1);
let params = &input.generics.params;
@@ -119,6 +119,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
fn lint_suppress_with_body() -> Attribute {
parse_quote! {
#[allow(
+ clippy::async_yields_async,
clippy::let_unit_value,
clippy::no_effect_underscore_binding,
clippy::shadow_same,
@@ -166,7 +167,7 @@ fn transform_sig(
ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)),
};
- let mut lifetimes = CollectLifetimes::new("'life", default_span);
+ let mut lifetimes = CollectLifetimes::new("'life");
for arg in sig.inputs.iter_mut() {
match arg {
FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg),
@@ -297,10 +298,16 @@ fn transform_sig(
}) => {}
FnArg::Receiver(arg) => arg.mutability = None,
FnArg::Typed(arg) => {
- if let Pat::Ident(ident) = &mut *arg.pat {
- ident.by_ref = None;
- ident.mutability = None;
- } else {
+ let type_is_reference = match *arg.ty {
+ Type::Reference(_) => true,
+ _ => false,
+ };
+ if let Pat::Ident(pat) = &mut *arg.pat {
+ if pat.ident == "self" || !type_is_reference {
+ pat.by_ref = None;
+ pat.mutability = None;
+ }
+ } else if !type_is_reference {
let positional = positional_arg(i, &arg.pat);
let m = mut_pat(&mut arg.pat);
arg.pat = parse_quote!(#m #positional);
@@ -362,6 +369,12 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
quote!(let #mutability #ident = #self_token;)
}
FnArg::Typed(arg) => {
+ // If there is a #[cfg(...)] attribute that selectively enables
+ // the parameter, forward it to the variable.
+ //
+ // This is currently not applied to the `self` parameter.
+ let attrs = arg.attrs.iter().filter(|attr| attr.path.is_ident("cfg"));
+
if let Pat::Ident(PatIdent {
ident, mutability, ..
}) = &*arg.pat
@@ -370,16 +383,32 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
self_span = Some(ident.span());
let prefixed = Ident::new("__self", ident.span());
quote!(let #mutability #prefixed = #ident;)
+ } else if let Type::Reference(_) = *arg.ty {
+ quote!()
} else {
- quote!(let #mutability #ident = #ident;)
+ quote! {
+ #(#attrs)*
+ let #mutability #ident = #ident;
+ }
}
+ } else if let Type::Reference(_) = *arg.ty {
+ quote!()
} else {
let pat = &arg.pat;
let ident = positional_arg(i, pat);
if let Pat::Wild(_) = **pat {
- quote!(let #ident = #ident;)
+ quote! {
+ #(#attrs)*
+ let #ident = #ident;
+ }
} else {
- quote!(let #pat = #ident;)
+ quote! {
+ #(#attrs)*
+ let #pat = {
+ let #ident = #ident;
+ #ident
+ };
+ }
}
}
}
diff --git a/src/lifetime.rs b/src/lifetime.rs
index 8e4ec38..86eac24 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream};
use std::mem;
use syn::visit_mut::{self, VisitMut};
use syn::{
- parse_quote_spanned, token, Expr, GenericArgument, Lifetime, Receiver, ReturnType, Type,
+ parse_quote_spanned, token, Expr, GenericArgument, Lifetime, Receiver, ReturnType, Token, Type,
TypeBareFn, TypeImplTrait, TypeParen, TypePtr, TypeReference,
};
@@ -10,22 +10,20 @@ pub struct CollectLifetimes {
pub elided: Vec<Lifetime>,
pub explicit: Vec<Lifetime>,
pub name: &'static str,
- pub default_span: Span,
}
impl CollectLifetimes {
- pub fn new(name: &'static str, default_span: Span) -> Self {
+ pub fn new(name: &'static str) -> Self {
CollectLifetimes {
elided: Vec::new(),
explicit: Vec::new(),
name,
- default_span,
}
}
- fn visit_opt_lifetime(&mut self, lifetime: &mut Option<Lifetime>) {
+ fn visit_opt_lifetime(&mut self, reference: Token![&], lifetime: &mut Option<Lifetime>) {
match lifetime {
- None => *lifetime = Some(self.next_lifetime(None)),
+ None => *lifetime = Some(self.next_lifetime(reference.span)),
Some(lifetime) => self.visit_lifetime(lifetime),
}
}
@@ -38,9 +36,8 @@ impl CollectLifetimes {
}
}
- fn next_lifetime<S: Into<Option<Span>>>(&mut self, span: S) -> Lifetime {
+ fn next_lifetime(&mut self, span: Span) -> Lifetime {
let name = format!("{}{}", self.name, self.elided.len());
- let span = span.into().unwrap_or(self.default_span);
let life = Lifetime::new(&name, span);
self.elided.push(life.clone());
life
@@ -49,13 +46,13 @@ impl CollectLifetimes {
impl VisitMut for CollectLifetimes {
fn visit_receiver_mut(&mut self, arg: &mut Receiver) {
- if let Some((_, lifetime)) = &mut arg.reference {
- self.visit_opt_lifetime(lifetime);
+ if let Some((reference, lifetime)) = &mut arg.reference {
+ self.visit_opt_lifetime(*reference, lifetime);
}
}
fn visit_type_reference_mut(&mut self, ty: &mut TypeReference) {
- self.visit_opt_lifetime(&mut ty.lifetime);
+ self.visit_opt_lifetime(ty.and_token, &mut ty.lifetime);
visit_mut::visit_type_reference_mut(self, ty);
}
diff --git a/tests/test.rs b/tests/test.rs
index 23d8f80..458904e 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -2,6 +2,7 @@
async_trait_nightly_testing,
feature(min_specialization, type_alias_impl_trait)
)]
+#![deny(rust_2021_compatibility)]
#![allow(
clippy::let_unit_value,
clippy::missing_panics_doc,
@@ -1461,3 +1462,125 @@ pub mod issue210 {
async fn f(self: Arc<Self>) {}
}
}
+
+// https://github.com/dtolnay/async-trait/issues/226
+pub mod issue226 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Trait {
+ async fn cfg_param(&self, param: u8);
+ async fn cfg_param_wildcard(&self, _: u8);
+ async fn cfg_param_tuple(&self, (left, right): (u8, u8));
+ }
+
+ struct Struct;
+
+ #[async_trait]
+ impl Trait for Struct {
+ async fn cfg_param(&self, #[cfg(any())] param: u8, #[cfg(all())] _unused: u8) {}
+
+ async fn cfg_param_wildcard(&self, #[cfg(any())] _: u8, #[cfg(all())] _: u8) {}
+
+ async fn cfg_param_tuple(
+ &self,
+ #[cfg(any())] (left, right): (u8, u8),
+ #[cfg(all())] (_left, _right): (u8, u8),
+ ) {
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/232
+pub mod issue232 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Generic<T> {
+ async fn take_ref(&self, thing: &T);
+ }
+
+ pub struct One;
+
+ #[async_trait]
+ impl<T> Generic<T> for One {
+ async fn take_ref(&self, _: &T) {}
+ }
+
+ pub struct Two;
+
+ #[async_trait]
+ impl<T: Sync> Generic<(T, T)> for Two {
+ async fn take_ref(&self, (a, b): &(T, T)) {
+ let _ = a;
+ let _ = b;
+ }
+ }
+
+ pub struct Three;
+
+ #[async_trait]
+ impl<T> Generic<(T, T, T)> for Three {
+ async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {}
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/234
+pub mod issue234 {
+ use async_trait::async_trait;
+
+ pub struct Droppable;
+
+ impl Drop for Droppable {
+ fn drop(&mut self) {}
+ }
+
+ pub struct Tuple<T, U>(T, U);
+
+ #[async_trait]
+ pub trait Trait {
+ async fn f(arg: Tuple<Droppable, i32>);
+ }
+
+ pub struct UnderscorePattern;
+
+ #[async_trait]
+ impl Trait for UnderscorePattern {
+ async fn f(Tuple(_, _int): Tuple<Droppable, i32>) {}
+ }
+
+ pub struct DotDotPattern;
+
+ #[async_trait]
+ impl Trait for DotDotPattern {
+ async fn f(Tuple { 1: _int, .. }: Tuple<Droppable, i32>) {}
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/236
+pub mod issue236 {
+ #![deny(clippy::async_yields_async)]
+ #![allow(clippy::manual_async_fn)]
+
+ use async_trait::async_trait;
+ use std::future::{self, Future, Ready};
+
+ // Does not trigger the lint.
+ pub async fn async_fn() -> Ready<()> {
+ future::ready(())
+ }
+
+ #[allow(clippy::async_yields_async)]
+ pub fn impl_future_fn() -> impl Future<Output = Ready<()>> {
+ async { future::ready(()) }
+ }
+
+ // The async_trait attribute turns the former into the latter, so we make it
+ // put its own allow(async_yeilds_async) to remain consistent with async fn.
+ #[async_trait]
+ pub trait Trait {
+ async fn f() -> Ready<()> {
+ future::ready(())
+ }
+ }
+}
diff --git a/tests/ui/lifetime-defined-here.rs b/tests/ui/lifetime-defined-here.rs
new file mode 100644
index 0000000..237cf66
--- /dev/null
+++ b/tests/ui/lifetime-defined-here.rs
@@ -0,0 +1,23 @@
+use async_trait::async_trait;
+
+#[async_trait]
+trait Foo {
+ async fn bar(&self, x: &str, y: &'_ str) -> &'static str;
+}
+
+struct S(String);
+
+#[async_trait]
+impl Foo for S {
+ async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
+ if false {
+ &self.0
+ } else if false {
+ x
+ } else {
+ y
+ }
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/lifetime-defined-here.stderr b/tests/ui/lifetime-defined-here.stderr
new file mode 100644
index 0000000..9ffef5b
--- /dev/null
+++ b/tests/ui/lifetime-defined-here.stderr
@@ -0,0 +1,29 @@
+error: lifetime may not live long enough
+ --> tests/ui/lifetime-defined-here.rs:12:49
+ |
+12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
+ | - ^^^^^^^^^^^^ type annotation requires that `'life0` must outlive `'static`
+ | |
+ | lifetime `'life0` defined here
+
+error: lifetime may not live long enough
+ --> tests/ui/lifetime-defined-here.rs:12:49
+ |
+12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
+ | - ^^^^^^^^^^^^ type annotation requires that `'life1` must outlive `'static`
+ | |
+ | lifetime `'life1` defined here
+
+error: lifetime may not live long enough
+ --> tests/ui/lifetime-defined-here.rs:12:49
+ |
+12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
+ | -- ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
+ | |
+ | lifetime `'life2` defined here
+
+help: the following changes may resolve your lifetime errors
+ |
+ = help: replace `'life0` with `'static`
+ = help: replace `'life1` with `'static`
+ = help: replace `'life2` with `'static`