fn require_sync(_: T) {} fn require_send_sync(_: T) {} struct NotSend(*const ()); unsafe impl Sync for NotSend {} #[test] fn test_btree_map() { // Tests of this form are prone to https://github.com/rust-lang/rust/issues/64552. // // In theory the async block's future would be Send if the value we hold // across the await point is Send, and Sync if the value we hold across the // await point is Sync. // // We test autotraits in this convoluted way, instead of a straightforward // `require_send_sync::()`, because the interaction with // generators exposes some current limitations in rustc's ability to prove a // lifetime bound on the erased generator witness types. See the above link. // // A typical way this would surface in real code is: // // fn spawn(_: T) {} // // async fn f() { // let map = BTreeMap::>::new(); // for _ in &map { // async {}.await; // } // } // // fn main() { // spawn(f()); // } // // where with some unintentionally overconstrained Send impls in alloc's // internals, the future might incorrectly not be Send even though every // single type involved in the program is Send and Sync. require_send_sync(async { let _v = None::>; async {}.await; }); // Testing like this would not catch all issues that the above form catches. require_send_sync(None::>); require_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::< alloc::collections::btree_map::DrainFilter< '_, &u32, &u32, fn(&&u32, &mut &u32) -> bool, >, >; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); } #[test] fn test_btree_set() { require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None:: bool>>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); } #[test] fn test_binary_heap() { require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); } #[test] fn test_linked_list() { require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); // FIXME /* require_send_sync(async { let _v = None:: bool>>; async {}.await; }); */ require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); } #[test] fn test_vec_deque() { require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); require_send_sync(async { let _v = None::>; async {}.await; }); }