|
| 1 | +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +#![allow(unused_mut)] |
| 12 | +#![feature(collections)] |
| 13 | + |
| 14 | +extern crate collections; |
| 15 | + |
| 16 | +use collections::BinaryHeap; |
| 17 | +use collections::{BitSet, BitVec}; |
| 18 | +use collections::{BTreeMap, BTreeSet}; |
| 19 | +use collections::EnumSet; |
| 20 | +use collections::LinkedList; |
| 21 | +use collections::Vec; |
| 22 | +use collections::VecDeque; |
| 23 | +use collections::VecMap; |
| 24 | + |
| 25 | +use collections::Bound::Included; |
| 26 | +use collections::enum_set::CLike; |
| 27 | +use std::mem; |
| 28 | + |
| 29 | +fn is_sync<T>(_: T) where T: Sync {} |
| 30 | +fn is_send<T>(_: T) where T: Send {} |
| 31 | + |
| 32 | +macro_rules! all_sync_send { |
| 33 | + ($ctor:expr, $($iter:ident),+) => ({ |
| 34 | + $( |
| 35 | + let mut x = $ctor; |
| 36 | + is_sync(x.$iter()); |
| 37 | + let mut y = $ctor; |
| 38 | + is_send(y.$iter()); |
| 39 | + )+ |
| 40 | + }) |
| 41 | +} |
| 42 | + |
| 43 | +macro_rules! is_sync_send { |
| 44 | + ($ctor:expr, $iter:ident($($param:expr),+)) => ({ |
| 45 | + let mut x = $ctor; |
| 46 | + is_sync(x.$iter($( $param ),+)); |
| 47 | + let mut y = $ctor; |
| 48 | + is_send(y.$iter($( $param ),+)); |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +fn main() { |
| 53 | + // The iterator "generator" list should exhaust what corresponding |
| 54 | + // implementations have where `Sync` and `Send` semantics apply. |
| 55 | + all_sync_send!(BinaryHeap::<usize>::new(), iter, drain, into_iter); |
| 56 | + |
| 57 | + all_sync_send!(BitVec::new(), iter); |
| 58 | + |
| 59 | + all_sync_send!(BitSet::new(), iter); |
| 60 | + is_sync_send!(BitSet::new(), union(&BitSet::new())); |
| 61 | + is_sync_send!(BitSet::new(), intersection(&BitSet::new())); |
| 62 | + is_sync_send!(BitSet::new(), difference(&BitSet::new())); |
| 63 | + is_sync_send!(BitSet::new(), symmetric_difference(&BitSet::new())); |
| 64 | + |
| 65 | + all_sync_send!(BTreeMap::<usize, usize>::new(), iter, iter_mut, into_iter, keys, values); |
| 66 | + is_sync_send!(BTreeMap::<usize, usize>::new(), range(Included(&0), Included(&9))); |
| 67 | + is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut(Included(&0), Included(&9))); |
| 68 | + |
| 69 | + all_sync_send!(BTreeSet::<usize>::new(), iter, into_iter); |
| 70 | + is_sync_send!(BTreeSet::<usize>::new(), range(Included(&0), Included(&9))); |
| 71 | + is_sync_send!(BTreeSet::<usize>::new(), difference(&BTreeSet::<usize>::new())); |
| 72 | + is_sync_send!(BTreeSet::<usize>::new(), symmetric_difference(&BTreeSet::<usize>::new())); |
| 73 | + is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new())); |
| 74 | + is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new())); |
| 75 | + |
| 76 | + all_sync_send!(LinkedList::<usize>::new(), iter, iter_mut, into_iter); |
| 77 | + |
| 78 | + #[derive(Copy)] |
| 79 | + #[repr(usize)] |
| 80 | + #[allow(dead_code)] |
| 81 | + enum Foo { A, B, C } |
| 82 | + impl CLike for Foo { |
| 83 | + fn to_usize(&self) -> usize { |
| 84 | + *self as usize |
| 85 | + } |
| 86 | + |
| 87 | + fn from_usize(v: usize) -> Foo { |
| 88 | + unsafe { mem::transmute(v) } |
| 89 | + } |
| 90 | + } |
| 91 | + all_sync_send!(EnumSet::<Foo>::new(), iter); |
| 92 | + |
| 93 | + all_sync_send!(VecDeque::<usize>::new(), iter, iter_mut, drain, into_iter); |
| 94 | + |
| 95 | + all_sync_send!(VecMap::<usize>::new(), iter, iter_mut, drain, into_iter, keys, values); |
| 96 | + |
| 97 | + all_sync_send!(Vec::<usize>::new(), into_iter, drain); |
| 98 | +} |
0 commit comments