You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The title might be confusing, but here is my test code:
#![feature(async_await)]use std::sync::{Arc,Mutex};asyncfndiv2(x:usize) -> usize{
x / 2}asyncfnfoo_pass(m:Arc<Mutex<usize>>) -> usize{let y = {let x = m.lock().unwrap();// x: !Send*x + 1};// x is dropped herediv2(y).await}asyncfnfoo_fail(m:Arc<Mutex<usize>>) -> usize{let x = m.lock().unwrap();// x: !Sendlet y = *x + 1;drop(x);// x is dropped here (maybe)div2(y).await}structCheckSend<T:Send>(T);pubfnpass(){let m = Arc::new(Mutex::new(5));let _ = CheckSend(foo_pass(m.clone()));}pubfnfail(){let m = Arc::new(Mutex::new(5));let _ = CheckSend(foo_fail(m.clone()));}
error[E0277]: `std::sync::MutexGuard<'_, usize>` cannot be sent between threads safely
--> src/lib.rs:32:13
|
32 | let _ = CheckSend(foo_fail(m.clone()));
| ^^^^^^^^^ `std::sync::MutexGuard<'_, usize>` cannot be sent between threads safely
|
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, usize>`
= note: required because it appears within the type `for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}`
= note: required because it appears within the type `[static generator@src/lib.rs:16:50: 21:2 m:std::sync::Arc<std::sync::Mutex<usize>> for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}]`
= note: required because it appears within the type `std::future::GenFuture<[static generator@src/lib.rs:16:50: 21:2 m:std::sync::Arc<std::sync::Mutex<usize>> for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}]>`
= note: required because it appears within the type `impl std::future::Future`
= note: required because it appears within the type `impl std::future::Future`
note: required by `CheckSend`
--> src/lib.rs:23:1
|
23 | struct CheckSend<T: Send>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: `std::sync::MutexGuard<'_, usize>` cannot be sent between threads safely
--> src/lib.rs:32:13
|
32 | let _ = CheckSend(foo_fail(m.clone()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::sync::MutexGuard<'_, usize>` cannot be sent between threads safely
|
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, usize>`
= note: required because it appears within the type `for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}`
= note: required because it appears within the type `[static generator@src/lib.rs:16:50: 21:2 m:std::sync::Arc<std::sync::Mutex<usize>> for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}]`
= note: required because it appears within the type `std::future::GenFuture<[static generator@src/lib.rs:16:50: 21:2 m:std::sync::Arc<std::sync::Mutex<usize>> for<'r> {std::sync::Arc<std::sync::Mutex<usize>>, std::sync::MutexGuard<'r, usize>, usize, impl std::future::Future, ()}]>`
= note: required because it appears within the type `impl std::future::Future`
= note: required because it appears within the type `impl std::future::Future`
note: required by `CheckSend`
--> src/lib.rs:23:1
|
23 | struct CheckSend<T: Send>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The text was updated successfully, but these errors were encountered:
The title might be confusing, but here is my test code:
Playground
The text was updated successfully, but these errors were encountered: