From 80a9c2c8af3073d62c840ca808107b80378ded6a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 22 Jan 2023 13:51:01 -0800 Subject: [PATCH 1/2] Add regression test for issue 234 Currently fails to compile: error: changes to closure capture in Rust 2021 will affect drop order --> tests/test.rs:1549:59 | 1549 | async fn f(Tuple(_, _int): Tuple) {} | -------------- ^- | | | | | in Rust 2018, `__arg0` is dropped here, but in Rust 2021, only `__arg0.1` will be dropped here as part of the closure | in Rust 2018, this closure captures all of `__arg0`, but in Rust 2021, it will only capture `__arg0.1` | = note: for more information, see note: the lint level is defined here --> tests/test.rs:5:9 | 5 | #![deny(rust_2021_compatibility)] | ^^^^^^^^^^^^^^^^^^^^^^^ = note: `#[deny(rust_2021_incompatible_closure_captures)]` implied by `#[deny(rust_2021_compatibility)]` help: add a dummy let to cause `__arg0` to be fully captured | 1549 | async fn f(Tuple(_, _int): Tuple) { let _ = &__arg0;} | ++++++++++++++++ error: changes to closure capture in Rust 2021 will affect drop order --> tests/test.rs:1556:66 | 1556 | async fn f(Tuple { 1: _int, .. }: Tuple) {} | --------------------- ^- | | | | | in Rust 2018, `__arg0` is dropped here, but in Rust 2021, only `__arg0.1` will be dropped here as part of the closure | in Rust 2018, this closure captures all of `__arg0`, but in Rust 2021, it will only capture `__arg0.1` | = note: for more information, see help: add a dummy let to cause `__arg0` to be fully captured | 1556 | async fn f(Tuple { 1: _int, .. }: Tuple) { let _ = &__arg0;} | ++++++++++++++++ --- tests/test.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 211387a..2d7dc65 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, @@ -1523,3 +1524,35 @@ pub mod issue232 { 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); + + #[async_trait] + pub trait Trait { + async fn f(arg: Tuple); + } + + pub struct UnderscorePattern; + + #[async_trait] + impl Trait for UnderscorePattern { + async fn f(Tuple(_, _int): Tuple) {} + } + + pub struct DotDotPattern; + + #[async_trait] + impl Trait for DotDotPattern { + async fn f(Tuple { 1: _int, .. }: Tuple) {} + } +} From 1c2e90a9846fa386d8a28415eaef09103c663106 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 22 Jan 2023 13:52:02 -0800 Subject: [PATCH 2/2] Make expansion of nested _ and .. patterns edition independent --- src/expand.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/expand.rs b/src/expand.rs index 7747e68..c2cfacb 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -403,7 +403,10 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) { } else { quote! { #(#attrs)* - let #pat = #ident; + let #pat = { + let #ident = #ident; + #ident + }; } } }