Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 1 | error: future cannot be sent between threads safely |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 2 | --> tests/ui/send-not-implemented.rs:8:26 |
Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 3 | | |
| 4 | 8 | async fn test(&self) { |
| 5 | | __________________________^ |
| 6 | 9 | | let mutex = Mutex::new(()); |
| 7 | 10 | | let _guard = mutex.lock().unwrap(); |
| 8 | 11 | | f().await; |
| 9 | 12 | | } |
Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 10 | | |_____^ future created by async block is not `Send` |
Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 11 | | |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 12 | = help: within `impl Future<Output = [async output]>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>` |
Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 13 | note: future is not `Send` as this value is used across an await |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 14 | --> tests/ui/send-not-implemented.rs:11:9 |
Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 15 | | |
| 16 | 10 | let _guard = mutex.lock().unwrap(); |
Chih-Hung Hsieh | f8b73ea | 2020-10-26 13:16:52 -0700 | [diff] [blame] | 17 | | ------ has type `MutexGuard<'_, ()>` which is not `Send` |
Andrew Walbran | d1b91c7 | 2020-08-11 17:12:08 +0100 | [diff] [blame] | 18 | 11 | f().await; |
| 19 | | ^^^^^^^^^ await occurs here, with `_guard` maybe used later |
| 20 | 12 | } |
| 21 | | - `_guard` is later dropped here |
Chih-Hung Hsieh | f8b73ea | 2020-10-26 13:16:52 -0700 | [diff] [blame] | 22 | = note: required for the cast to the object type `dyn Future<Output = ()> + Send` |
Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 23 | |
| 24 | error: future cannot be sent between threads safely |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 25 | --> tests/ui/send-not-implemented.rs:14:38 |
Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 26 | | |
| 27 | 14 | async fn test_ret(&self) -> bool { |
| 28 | | ______________________________________^ |
| 29 | 15 | | let mutex = Mutex::new(()); |
| 30 | 16 | | let _guard = mutex.lock().unwrap(); |
| 31 | 17 | | f().await; |
| 32 | 18 | | true |
| 33 | 19 | | } |
| 34 | | |_____^ future created by async block is not `Send` |
| 35 | | |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 36 | = help: within `impl Future<Output = [async output]>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>` |
Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 37 | note: future is not `Send` as this value is used across an await |
David LeGare | ffb07e7 | 2022-03-01 18:48:27 +0000 | [diff] [blame] | 38 | --> tests/ui/send-not-implemented.rs:17:9 |
Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 39 | | |
| 40 | 16 | let _guard = mutex.lock().unwrap(); |
| 41 | | ------ has type `MutexGuard<'_, ()>` which is not `Send` |
| 42 | 17 | f().await; |
| 43 | | ^^^^^^^^^ await occurs here, with `_guard` maybe used later |
| 44 | 18 | true |
| 45 | 19 | } |
| 46 | | - `_guard` is later dropped here |
| 47 | = note: required for the cast to the object type `dyn Future<Output = bool> + Send` |