Skip to content

Commit cf5bc6e

Browse files
committed
Add test of non-Send async fn default with return type
1 parent 16e5008 commit cf5bc6e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/ui/send-not-implemented.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ trait Test {
1010
let _guard = mutex.lock().unwrap();
1111
f().await;
1212
}
13+
14+
async fn test_ret(&self) -> bool {
15+
let mutex = Mutex::new(());
16+
let _guard = mutex.lock().unwrap();
17+
f().await;
18+
true
19+
}
1320
}
1421

1522
fn main() {}

tests/ui/send-not-implemented.stderr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,22 @@ note: future is not `Send` as this value is used across an await
2020
12 | }
2121
| - `_guard` is later dropped here
2222
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
23+
24+
error: future cannot be sent between threads safely
25+
--> $DIR/send-not-implemented.rs:14:33
26+
|
27+
14 | async fn test_ret(&self) -> bool {
28+
| ^^^^ future created by async block is not `Send`
29+
|
30+
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
31+
note: future is not `Send` as this value is used across an await
32+
--> $DIR/send-not-implemented.rs:17:9
33+
|
34+
14 | async fn test_ret(&self) -> bool {
35+
| - `_guard` is later dropped here
36+
15 | let mutex = Mutex::new(());
37+
16 | let _guard = mutex.lock().unwrap();
38+
| ------ has type `MutexGuard<'_, ()>` which is not `Send`
39+
17 | f().await;
40+
| ^^^^^^^^^ await occurs here, with `_guard` maybe used later
41+
= note: required for the cast to the object type `dyn Future<Output = bool> + Send`

0 commit comments

Comments
 (0)