Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested _ and .. patterns under 2018 edition can trigger rust_2021_compatibility warning #234

Closed
dtolnay opened this issue Jan 22, 2023 · 0 comments · Fixed by #235
Closed
Labels
bug Something isn't working

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jan 22, 2023

The code generated by async-trait should never exhibit edition sensitive behavior differences. The fact that async-trait involves the use of move closures internally is an implementation detail. If the behavior is sensitive to edition of the caller's crate, that is a bug in async-trait.

#![warn(rust_2021_compatibility)]

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 create(arg: Tuple<Droppable, i32>);
}

pub struct Struct;
#[async_trait]
impl Trait for Struct {
    async fn create(Tuple(_, _int): Tuple<Droppable, i32>) {}
}
warning: changes to closure capture in Rust 2021 will affect drop order
  --> src/main.rs:22:60
   |
22 |     async fn create(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
  --> src/main.rs:1:9
   |
1  | #![warn(rust_2021_compatibility)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
help: add a dummy let to cause `__arg0` to be fully captured
   |
22 |     async fn create(Tuple(_, _int): Tuple<Droppable, i32>) { let _ = &__arg0;}
   |                                                              ++++++++++++++++
#[async_trait]
impl Trait for Struct {
    async fn create(Tuple { 1: _int, .. }: Tuple<Droppable, i32>) {}
}
warning: changes to closure capture in Rust 2021 will affect drop order
  --> src/main.rs:22:67
   |
22 |     async fn create(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>
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(rust_2021_compatibility)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
help: add a dummy let to cause `__arg0` to be fully captured
   |
22 |     async fn create(Tuple { 1: _int, .. }: Tuple<Droppable, i32>) { let _ = &__arg0;}
   |                                                                     ++++++++++++++++
@dtolnay dtolnay added the bug Something isn't working label Jan 22, 2023
crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Feb 1, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [async-trait](https://github.com/dtolnay/async-trait) | dependencies | patch | `0.1.62` -> `0.1.64` |

---

### Release Notes

<details>
<summary>dtolnay/async-trait</summary>

### [`v0.1.64`](https://github.com/dtolnay/async-trait/releases/tag/0.1.64)

[Compare Source](dtolnay/async-trait@0.1.63...0.1.64)

-   Suppress async_yields_async clippy correctness lint in generated code ([#&#8203;236](dtolnay/async-trait#236), [#&#8203;237](dtolnay/async-trait#237))

### [`v0.1.63`](https://github.com/dtolnay/async-trait/releases/tag/0.1.63)

[Compare Source](dtolnay/async-trait@0.1.62...0.1.63)

-   Do not require Sync on unused shared reference arguments ([#&#8203;232](dtolnay/async-trait#232), [#&#8203;233](dtolnay/async-trait#233))
-   Make expansion of nested `_` and `..` patterns edition independent ([#&#8203;234](dtolnay/async-trait#234), [#&#8203;235](dtolnay/async-trait#235))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTQuMSIsInVwZGF0ZWRJblZlciI6IjM0LjExNi4xIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Co-authored-by: crapStone <crapstone@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1750
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant