2 // compile-flags: --crate-type lib -Zdrop-tracking
4 use std::{cell::RefCell, fmt::Debug, rc::Rc};
6 fn non_sync() -> impl Debug {
10 fn non_send() -> impl Debug {
14 fn take_ref<T>(_: &T) {}
18 async fn fut_arg<T>(_: T) {}
20 async fn local_dropped_before_await() {
21 // this is okay now because of the drop
27 async fn non_send_temporary_in_match() {
28 // We could theoretically make this work as well (produce a `Send` future)
29 // for scrutinees / temporaries that can or will
30 // be dropped prior to the match body
31 // (e.g. `Copy` types).
32 match Some(non_send()) {
33 Some(_) => fut().await,
38 fn get_formatter() -> std::fmt::Formatter<'static> {
42 async fn non_sync_with_method_call() {
43 let f: &mut std::fmt::Formatter = &mut get_formatter();
44 // It would by nice for this to work.
45 if non_sync().fmt(f).unwrap() == () {
50 async fn non_sync_with_method_call_panic() {
51 let f: &mut std::fmt::Formatter = panic!();
52 if non_sync().fmt(f).unwrap() == () {
57 async fn non_sync_with_method_call_infinite_loop() {
58 let f: &mut std::fmt::Formatter = loop {};
59 if non_sync().fmt(f).unwrap() == () {
64 fn assert_send(_: impl Send) {}
66 pub fn pass_assert() {
67 assert_send(local_dropped_before_await());
68 assert_send(non_send_temporary_in_match());
69 //~^ ERROR future cannot be sent between threads safely
70 assert_send(non_sync_with_method_call());
71 //~^ ERROR future cannot be sent between threads safely
72 assert_send(non_sync_with_method_call_panic());
73 assert_send(non_sync_with_method_call_infinite_loop());