Skip to content

Compile success when generic parameter is possibly not "Send", but compile fail if said parameter is in a tuple #280

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

Open
david0u0 opened this issue Dec 30, 2024 · 0 comments

Comments

@david0u0
Copy link

david0u0 commented Dec 30, 2024

async_trait ersion: 0.1.83
rustc version: rustc 1.84.0-beta.5 (0857a8e32 2024-12-27)


Below is the minimum code that can reproduce this. With the function "test_success", async trait doesn't care about "S" being Send or not, but when I put it into a tuple (bool, &mut S), suddenly it starts to complain that "S" cannot be send between threads.

use async_trait::async_trait;

#[async_trait]
trait Test<S> {
    async fn test_success(&self, _s: &mut S) {}
    // async fn test_fail(&self, _s: (bool, &mut S)) {}
}

Here's the error message:

   Compiling playground v0.0.1 (/playground)
error[E0277]: `S` cannot be sent between threads safely
 --> src/lib.rs:6:51
  |
6 |     async fn test_fail(&self, _s: (bool, &mut S)) {}
  |                                                   ^^
  |                                                   |
  |                                                   `S` cannot be sent between threads safely
  |                                                   within this `{async block@src/lib.rs:6:51: 6:53}`
  |
  = note: required because it appears within the type `&mut S`
  = note: required because it appears within the type `(bool, &mut S)`
note: required because it's used within this `async` block
 --> src/lib.rs:6:51
  |
6 |     async fn test_fail(&self, _s: (bool, &mut S)) {}
  |                                                   ^^
  = note: required for the cast from `Pin<Box<{async block@src/lib.rs:6:51: 6:53}>>` to `Pin<Box<(dyn Future<Output = ()> + Send + 'async_trait)>>`
help: consider restricting type parameter `S`
  |
4 | trait Test<S: std::marker::Send> {
  |             +++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error

I'm not sure what should be the correct behavior, but these two scenario seem logically the same. So I think they should either both compile fail or pass.

Thanks for this amazing crate!

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

No branches or pull requests

1 participant