- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: playground
use async_trait::async_trait; // 0.1.50
use serde::Serialize;
#[async_trait]
trait Foo {
    async fn bar(x: &(impl Serialize + Send));
}
#[async_trait]
impl Foo for () {
    async fn bar(x: &(impl Serialize + Send)) {
    }
}
fn main() { }The current output is:
error: future cannot be sent between threads safely
  --> src/main.rs:11:47
   |
11 |       async fn bar(x: &(impl Serialize + Send)) {
   |  _______________________________________________^
12 | |     }
   | |_____^ future created by async block is not `Send`
   |
note: captured value is not `Send`
  --> src/main.rs:11:18
   |
11 |     async fn bar(x: &(impl Serialize + Send)) {
   |                  ^ has type `&impl Serialize + Send` which is not `Send`
   = note: required for the cast to the object type `dyn Future<Output = ()> + Send`
help: consider further restricting this bound
   |
11 |     async fn bar(x: &(impl Serialize + Send + std::marker::Sync)) {
   |                                             ^^^^^^^^^^^^^^^^^^^
The compiler helpfully points out that Sync is required, but nonetheless @chazkiker2 and I both got confused by this error for some time before we noticed it. The suggestion was kind of buried by all the other details.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.