2020-03-24 19:23:50 -05:00
|
|
|
// edition:2018
|
2022-10-01 05:19:31 -05:00
|
|
|
// revisions: no_drop_tracking drop_tracking drop_tracking_mir
|
|
|
|
// [drop_tracking] compile-flags: -Zdrop-tracking
|
|
|
|
// [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
|
2020-03-24 19:23:50 -05:00
|
|
|
|
|
|
|
use std::{
|
|
|
|
cell::RefCell,
|
2022-09-13 16:36:45 -05:00
|
|
|
future::Future,
|
2020-03-24 19:23:50 -05:00
|
|
|
pin::Pin,
|
2022-09-13 16:36:45 -05:00
|
|
|
sync::Arc,
|
2020-03-24 19:23:50 -05:00
|
|
|
task::{Context, Poll},
|
|
|
|
};
|
|
|
|
|
|
|
|
fn require_send(_: impl Send) {}
|
|
|
|
|
|
|
|
struct Ready<T>(Option<T>);
|
2023-01-25 21:51:26 -06:00
|
|
|
impl<T: Unpin> Future for Ready<T> {
|
2020-03-24 19:23:50 -05:00
|
|
|
type Output = T;
|
|
|
|
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
|
|
|
|
Poll::Ready(self.0.take().unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn ready<T>(t: T) -> Ready<T> {
|
|
|
|
Ready(Some(t))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_non_send_future1() -> impl Future<Output = Arc<RefCell<i32>>> {
|
|
|
|
ready(Arc::new(RefCell::new(0)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test1() {
|
|
|
|
let send_fut = async {
|
|
|
|
let non_send_fut = make_non_send_future1();
|
|
|
|
let _ = non_send_fut.await;
|
|
|
|
ready(0).await;
|
|
|
|
};
|
|
|
|
require_send(send_fut);
|
|
|
|
//~^ ERROR future cannot be sent between threads
|
|
|
|
}
|
|
|
|
|
2020-04-01 21:04:55 -05:00
|
|
|
fn test1_no_let() {
|
|
|
|
let send_fut = async {
|
|
|
|
let _ = make_non_send_future1().await;
|
|
|
|
ready(0).await;
|
|
|
|
};
|
|
|
|
require_send(send_fut);
|
|
|
|
//~^ ERROR future cannot be sent between threads
|
|
|
|
}
|
|
|
|
|
2022-09-13 16:36:45 -05:00
|
|
|
async fn ready2<T>(t: T) -> T {
|
|
|
|
t
|
|
|
|
}
|
2020-03-24 19:23:50 -05:00
|
|
|
fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
|
|
|
|
ready2(Arc::new(RefCell::new(0)))
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:54:31 -05:00
|
|
|
// Ideally this test would have diagnostics similar to the test above, but right
|
|
|
|
// now it doesn't.
|
2020-03-24 19:23:50 -05:00
|
|
|
fn test2() {
|
|
|
|
let send_fut = async {
|
|
|
|
let non_send_fut = make_non_send_future2();
|
|
|
|
let _ = non_send_fut.await;
|
|
|
|
ready(0).await;
|
|
|
|
};
|
|
|
|
require_send(send_fut);
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR `RefCell<i32>` cannot be shared between threads safely
|
2020-03-24 19:23:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|