Skip to content

Commit

Permalink
Add regression test for issue 234
Browse files Browse the repository at this point in the history
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<Droppable, i32>) {}
         |                    --------------                         ^-
         |                    |                                       |
         |                    |                                       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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
    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<Droppable, i32>) { 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<Droppable, i32>) {}
         |                    ---------------------                         ^-
         |                    |                                              |
         |                    |                                              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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
    help: add a dummy let to cause `__arg0` to be fully captured
         |
    1556 |         async fn f(Tuple { 1: _int, .. }: Tuple<Droppable, i32>) { let _ = &__arg0;}
         |                                                                    ++++++++++++++++
  • Loading branch information
dtolnay committed Jan 22, 2023
1 parent 125917f commit 80a9c2c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>(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>) {}
}
}

0 comments on commit 80a9c2c

Please sign in to comment.