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

Defaulted method with self: Arc<Self> doesn't work #210

Closed
ChayimFriedman2 opened this issue Jul 3, 2022 · 0 comments · Fixed by #223
Closed

Defaulted method with self: Arc<Self> doesn't work #210

ChayimFriedman2 opened this issue Jul 3, 2022 · 0 comments · Fixed by #223

Comments

@ChayimFriedman2
Copy link

Arc generates a where Self: Send bound, but for Arc it is not enough - it requires also T: Sync to be Send. This make the following code failing to compile:

#[async_trait]
trait Trait {
    async fn foo(self: Arc<Self>) {}
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=add1c3d15459405538a453e3c9a504a6

error: future cannot be sent between threads safely
 --> src/lib.rs:7:35
  |
7 |     async fn foo(self: Arc<Self>) {}
  |                                   ^^ future created by async block is not `Send`
  |
note: captured value is not `Send`
 --> src/lib.rs:7:18
  |
7 |     async fn foo(self: Arc<Self>) {}
  |                  ^^^^ has type `Arc<Self>` which is not `Send`
  = note: required for the cast to the object type `dyn Future<Output = ()> + Send`

Adding Sync as a supertrait works, but ideally the macro should also add a Self: Sync bound (even though I don't know how it can identify Arc being used), or at least document that.

@ChayimFriedman2 ChayimFriedman2 changed the title Defaulted method with self: Arc<Self> don't work Defaulted method with self: Arc<Self> doesn't work Jul 3, 2022
crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Dec 2, 2022
This PR contains the following updates:

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

---

### Release Notes

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

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

[Compare Source](dtolnay/async-trait@0.1.58...0.1.59)

-   Support `self: Arc<Self>` async methods that have a default implementation provided by the trait ([#&#8203;210](dtolnay/async-trait#210))

</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:eyJjcmVhdGVkSW5WZXIiOiIzNC40MC4yIiwidXBkYXRlZEluVmVyIjoiMzQuNDcuMSJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1661
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
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
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant