2019-06-24 19:48:21 -05:00
|
|
|
// edition:2018
|
2023-05-07 13:38:52 -05:00
|
|
|
// compile-flags: --crate-type lib -Zdrop-tracking
|
2022-01-21 11:36:24 -06:00
|
|
|
|
2020-01-20 11:17:12 -06:00
|
|
|
use std::{cell::RefCell, fmt::Debug, rc::Rc};
|
2019-06-24 19:48:21 -05:00
|
|
|
|
2020-01-20 11:17:12 -06:00
|
|
|
fn non_sync() -> impl Debug {
|
|
|
|
RefCell::new(())
|
|
|
|
}
|
2019-06-24 19:48:21 -05:00
|
|
|
|
2020-01-20 11:17:12 -06:00
|
|
|
fn non_send() -> impl Debug {
|
|
|
|
Rc::new(())
|
|
|
|
}
|
2019-06-24 19:48:21 -05:00
|
|
|
|
|
|
|
fn take_ref<T>(_: &T) {}
|
|
|
|
|
|
|
|
async fn fut() {}
|
|
|
|
|
|
|
|
async fn fut_arg<T>(_: T) {}
|
|
|
|
|
|
|
|
async fn local_dropped_before_await() {
|
2021-10-20 18:42:53 -05:00
|
|
|
// this is okay now because of the drop
|
2019-06-24 19:48:21 -05:00
|
|
|
let x = non_send();
|
|
|
|
drop(x);
|
|
|
|
fut().await;
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn non_send_temporary_in_match() {
|
|
|
|
// We could theoretically make this work as well (produce a `Send` future)
|
|
|
|
// for scrutinees / temporaries that can or will
|
|
|
|
// be dropped prior to the match body
|
|
|
|
// (e.g. `Copy` types).
|
|
|
|
match Some(non_send()) {
|
|
|
|
Some(_) => fut().await,
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 17:05:38 -06:00
|
|
|
fn get_formatter() -> std::fmt::Formatter<'static> {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:48:21 -05:00
|
|
|
async fn non_sync_with_method_call() {
|
2021-12-17 17:05:38 -06:00
|
|
|
let f: &mut std::fmt::Formatter = &mut get_formatter();
|
|
|
|
// It would by nice for this to work.
|
|
|
|
if non_sync().fmt(f).unwrap() == () {
|
|
|
|
fut().await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn non_sync_with_method_call_panic() {
|
2019-06-24 19:48:21 -05:00
|
|
|
let f: &mut std::fmt::Formatter = panic!();
|
|
|
|
if non_sync().fmt(f).unwrap() == () {
|
|
|
|
fut().await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 17:05:38 -06:00
|
|
|
async fn non_sync_with_method_call_infinite_loop() {
|
2021-12-16 15:34:39 -06:00
|
|
|
let f: &mut std::fmt::Formatter = loop {};
|
|
|
|
if non_sync().fmt(f).unwrap() == () {
|
|
|
|
fut().await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:48:21 -05:00
|
|
|
fn assert_send(_: impl Send) {}
|
|
|
|
|
|
|
|
pub fn pass_assert() {
|
|
|
|
assert_send(local_dropped_before_await());
|
|
|
|
assert_send(non_send_temporary_in_match());
|
2019-10-06 17:14:34 -05:00
|
|
|
//~^ ERROR future cannot be sent between threads safely
|
2019-06-24 19:48:21 -05:00
|
|
|
assert_send(non_sync_with_method_call());
|
2021-12-17 17:05:38 -06:00
|
|
|
//~^ ERROR future cannot be sent between threads safely
|
|
|
|
assert_send(non_sync_with_method_call_panic());
|
|
|
|
assert_send(non_sync_with_method_call_infinite_loop());
|
2019-06-24 19:48:21 -05:00
|
|
|
}
|