Compile success when generic parameter is possibly not "Send", but compile fail if said parameter is in a tuple
- Dominant language
- Rust
- Stars
- 2.2k
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
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 {
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>` to `Pin + Send + 'async_trait)>>`
help: consider restricting type parameter `S`
|
4 | trait Test {
| +++++++++++++++++++
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!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.