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
|
2019-06-24 19:48:21 -05:00
|
|
|
// edition:2018
|
2022-10-01 05:19:31 -05:00
|
|
|
// compile-flags: --crate-type lib
|
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());
|
2023-01-25 21:51:26 -06:00
|
|
|
//[no_drop_tracking]~^ ERROR future cannot be sent between threads safely
|
2019-06-24 19:48:21 -05:00
|
|
|
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());
|
2023-01-25 21:51:26 -06:00
|
|
|
//[no_drop_tracking]~^ ERROR future cannot be sent between threads safely
|
2021-12-17 17:05:38 -06:00
|
|
|
assert_send(non_sync_with_method_call_infinite_loop());
|
2023-01-25 21:51:26 -06:00
|
|
|
//[no_drop_tracking]~^ ERROR future cannot be sent between threads safely
|
2019-06-24 19:48:21 -05:00
|
|
|
}
|