1 // revisions: no_drop_tracking drop_tracking drop_tracking_mir
2 // [drop_tracking] compile-flags: -Zdrop-tracking
3 // [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
5 // compile-flags: --crate-type lib
7 use std::{cell::RefCell, fmt::Debug, rc::Rc};
9 fn non_sync() -> impl Debug {
13 fn non_send() -> impl Debug {
17 fn take_ref<T>(_: &T) {}
21 async fn fut_arg<T>(_: T) {}
23 async fn local_dropped_before_await() {
24 // this is okay now because of the drop
30 async fn non_send_temporary_in_match() {
31 // We could theoretically make this work as well (produce a `Send` future)
32 // for scrutinees / temporaries that can or will
33 // be dropped prior to the match body
34 // (e.g. `Copy` types).
35 match Some(non_send()) {
36 Some(_) => fut().await,
41 fn get_formatter() -> std::fmt::Formatter<'static> {
45 async fn non_sync_with_method_call() {
46 let f: &mut std::fmt::Formatter = &mut get_formatter();
47 // It would by nice for this to work.
48 if non_sync().fmt(f).unwrap() == () {
53 async fn non_sync_with_method_call_panic() {
54 let f: &mut std::fmt::Formatter = panic!();
55 if non_sync().fmt(f).unwrap() == () {
60 async fn non_sync_with_method_call_infinite_loop() {
61 let f: &mut std::fmt::Formatter = loop {};
62 if non_sync().fmt(f).unwrap() == () {
67 fn assert_send(_: impl Send) {}
69 pub fn pass_assert() {
70 assert_send(local_dropped_before_await());
71 //[no_drop_tracking]~^ ERROR future cannot be sent between threads safely
72 assert_send(non_send_temporary_in_match());
73 //~^ ERROR future cannot be sent between threads safely
74 assert_send(non_sync_with_method_call());
75 //~^ ERROR future cannot be sent between threads safely
76 assert_send(non_sync_with_method_call_panic());
77 //[no_drop_tracking]~^ ERROR future cannot be sent between threads safely
78 assert_send(non_sync_with_method_call_infinite_loop());
79 //[no_drop_tracking]~^ ERROR future cannot be sent between threads safely