1 fn require_sync<T: Sync>(_: T) {}
2 fn require_send_sync<T: Send + Sync>(_: T) {}
4 struct NotSend(*const ());
5 unsafe impl Sync for NotSend {}
9 // Tests of this form are prone to https://github.com/rust-lang/rust/issues/64552.
11 // In theory the async block's future would be Send if the value we hold
12 // across the await point is Send, and Sync if the value we hold across the
13 // await point is Sync.
15 // We test autotraits in this convoluted way, instead of a straightforward
16 // `require_send_sync::<TypeIWantToTest>()`, because the interaction with
17 // generators exposes some current limitations in rustc's ability to prove a
18 // lifetime bound on the erased generator witness types. See the above link.
20 // A typical way this would surface in real code is:
22 // fn spawn<T: Future + Send>(_: T) {}
25 // let map = BTreeMap::<u32, Box<dyn Send + Sync>>::new();
35 // where with some unintentionally overconstrained Send impls in liballoc's
36 // internals, the future might incorrectly not be Send even though every
37 // single type involved in the program is Send and Sync.
38 require_send_sync(async {
39 let _v = None::<alloc::collections::btree_map::Iter<'_, &u32, &u32>>;
43 // Testing like this would not catch all issues that the above form catches.
44 require_send_sync(None::<alloc::collections::btree_map::Iter<'_, &u32, &u32>>);
47 let _v = None::<alloc::collections::btree_map::Iter<'_, u32, NotSend>>;
51 require_send_sync(async {
52 let _v = None::<alloc::collections::btree_map::BTreeMap<&u32, &u32>>;
56 require_send_sync(async {
58 alloc::collections::btree_map::DrainFilter<
62 fn(&&u32, &mut &u32) -> bool,
68 require_send_sync(async {
69 let _v = None::<alloc::collections::btree_map::Entry<'_, &u32, &u32>>;
73 require_send_sync(async {
74 let _v = None::<alloc::collections::btree_map::IntoIter<&u32, &u32>>;
78 require_send_sync(async {
79 let _v = None::<alloc::collections::btree_map::IntoKeys<&u32, &u32>>;
83 require_send_sync(async {
84 let _v = None::<alloc::collections::btree_map::IntoValues<&u32, &u32>>;
88 require_send_sync(async {
89 let _v = None::<alloc::collections::btree_map::Iter<'_, &u32, &u32>>;
93 require_send_sync(async {
94 let _v = None::<alloc::collections::btree_map::IterMut<'_, &u32, &u32>>;
98 require_send_sync(async {
99 let _v = None::<alloc::collections::btree_map::Keys<'_, &u32, &u32>>;
103 require_send_sync(async {
104 let _v = None::<alloc::collections::btree_map::OccupiedEntry<'_, &u32, &u32>>;
108 require_send_sync(async {
109 let _v = None::<alloc::collections::btree_map::OccupiedError<'_, &u32, &u32>>;
113 require_send_sync(async {
114 let _v = None::<alloc::collections::btree_map::Range<'_, &u32, &u32>>;
118 require_send_sync(async {
119 let _v = None::<alloc::collections::btree_map::RangeMut<'_, &u32, &u32>>;
123 require_send_sync(async {
124 let _v = None::<alloc::collections::btree_map::VacantEntry<'_, &u32, &u32>>;
128 require_send_sync(async {
129 let _v = None::<alloc::collections::btree_map::Values<'_, &u32, &u32>>;
133 require_send_sync(async {
134 let _v = None::<alloc::collections::btree_map::ValuesMut<'_, &u32, &u32>>;
140 fn test_btree_set() {
141 require_send_sync(async {
142 let _v = None::<alloc::collections::btree_set::BTreeSet<&u32>>;
146 require_send_sync(async {
147 let _v = None::<alloc::collections::btree_set::Difference<'_, &u32>>;
151 require_send_sync(async {
152 let _v = None::<alloc::collections::btree_set::DrainFilter<'_, &u32, fn(&&u32) -> bool>>;
156 require_send_sync(async {
157 let _v = None::<alloc::collections::btree_set::Intersection<'_, &u32>>;
161 require_send_sync(async {
162 let _v = None::<alloc::collections::btree_set::IntoIter<&u32>>;
166 require_send_sync(async {
167 let _v = None::<alloc::collections::btree_set::Iter<'_, &u32>>;
171 require_send_sync(async {
172 let _v = None::<alloc::collections::btree_set::Range<'_, &u32>>;
176 require_send_sync(async {
177 let _v = None::<alloc::collections::btree_set::SymmetricDifference<'_, &u32>>;
181 require_send_sync(async {
182 let _v = None::<alloc::collections::btree_set::Union<'_, &u32>>;
188 fn test_binary_heap() {
189 require_send_sync(async {
190 let _v = None::<alloc::collections::binary_heap::BinaryHeap<&u32>>;
194 require_send_sync(async {
195 let _v = None::<alloc::collections::binary_heap::Drain<'_, &u32>>;
199 require_send_sync(async {
200 let _v = None::<alloc::collections::binary_heap::DrainSorted<'_, &u32>>;
204 require_send_sync(async {
205 let _v = None::<alloc::collections::binary_heap::IntoIter<&u32>>;
209 require_send_sync(async {
210 let _v = None::<alloc::collections::binary_heap::IntoIterSorted<&u32>>;
214 require_send_sync(async {
215 let _v = None::<alloc::collections::binary_heap::Iter<'_, &u32>>;
219 require_send_sync(async {
220 let _v = None::<alloc::collections::binary_heap::PeekMut<'_, &u32>>;
226 fn test_linked_list() {
227 require_send_sync(async {
228 let _v = None::<alloc::collections::linked_list::Cursor<'_, &u32>>;
232 require_send_sync(async {
233 let _v = None::<alloc::collections::linked_list::CursorMut<'_, &u32>>;
239 require_send_sync(async {
241 None::<alloc::collections::linked_list::DrainFilter<'_, &u32, fn(&mut &u32) -> bool>>;
246 require_send_sync(async {
247 let _v = None::<alloc::collections::linked_list::IntoIter<&u32>>;
251 require_send_sync(async {
252 let _v = None::<alloc::collections::linked_list::Iter<'_, &u32>>;
256 require_send_sync(async {
257 let _v = None::<alloc::collections::linked_list::IterMut<'_, &u32>>;
261 require_send_sync(async {
262 let _v = None::<alloc::collections::linked_list::LinkedList<&u32>>;
268 fn test_vec_deque() {
269 require_send_sync(async {
270 let _v = None::<alloc::collections::vec_deque::Drain<'_, &u32>>;
274 require_send_sync(async {
275 let _v = None::<alloc::collections::vec_deque::IntoIter<&u32>>;
279 require_send_sync(async {
280 let _v = None::<alloc::collections::vec_deque::Iter<'_, &u32>>;
284 require_send_sync(async {
285 let _v = None::<alloc::collections::vec_deque::IterMut<'_, &u32>>;
289 require_send_sync(async {
290 let _v = None::<alloc::collections::vec_deque::VecDeque<&u32>>;