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.
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.
12 #![feature(collections)]
13 #![feature(drain, enumset, collections_bound, btree_range, vecmap)]
15 extern crate collections;
17 use collections::BinaryHeap;
18 use collections::{BTreeMap, BTreeSet};
19 use collections::EnumSet;
20 use collections::LinkedList;
21 use collections::String;
23 use collections::VecDeque;
24 use std::collections::HashMap;
25 use std::collections::HashSet;
27 use collections::Bound::Included;
28 use collections::enum_set::CLike;
31 fn is_sync<T>(_: T) where T: Sync {}
32 fn is_send<T>(_: T) where T: Send {}
34 macro_rules! all_sync_send {
35 ($ctor:expr, $($iter:ident),+) => ({
45 macro_rules! is_sync_send {
46 ($ctor:expr, $iter:ident($($param:expr),+)) => ({
48 is_sync(x.$iter($( $param ),+));
50 is_send(y.$iter($( $param ),+));
55 // The iterator "generator" list should exhaust what corresponding
56 // implementations have where `Sync` and `Send` semantics apply.
57 all_sync_send!(BinaryHeap::<usize>::new(), iter, drain, into_iter);
59 all_sync_send!(BTreeMap::<usize, usize>::new(), iter, iter_mut, into_iter, keys, values);
60 is_sync_send!(BTreeMap::<usize, usize>::new(), range((Included(&0), Included(&9))));
61 is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut((Included(&0), Included(&9))));
63 all_sync_send!(BTreeSet::<usize>::new(), iter, into_iter);
64 is_sync_send!(BTreeSet::<usize>::new(), range((Included(&0), Included(&9))));
65 is_sync_send!(BTreeSet::<usize>::new(), difference(&BTreeSet::<usize>::new()));
66 is_sync_send!(BTreeSet::<usize>::new(), symmetric_difference(&BTreeSet::<usize>::new()));
67 is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new()));
68 is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new()));
70 all_sync_send!(HashMap::<usize, usize>::new(), iter, iter_mut, drain, into_iter, keys, values);
71 all_sync_send!(HashSet::<usize>::new(), iter, drain, into_iter);
72 is_sync_send!(HashSet::<usize>::new(), difference(&HashSet::<usize>::new()));
73 is_sync_send!(HashSet::<usize>::new(), symmetric_difference(&HashSet::<usize>::new()));
74 is_sync_send!(HashSet::<usize>::new(), intersection(&HashSet::<usize>::new()));
75 is_sync_send!(HashSet::<usize>::new(), union(&HashSet::<usize>::new()));
77 all_sync_send!(LinkedList::<usize>::new(), iter, iter_mut, into_iter);
79 #[derive(Copy, Clone)]
84 fn to_usize(&self) -> usize {
88 fn from_usize(v: usize) -> Foo {
89 unsafe { mem::transmute(v) }
92 all_sync_send!(EnumSet::<Foo>::new(), iter);
94 all_sync_send!(VecDeque::<usize>::new(), iter, iter_mut, into_iter);
95 is_sync_send!(VecDeque::<usize>::new(), drain(..));
97 all_sync_send!(Vec::<usize>::new(), into_iter);
98 is_sync_send!(Vec::<usize>::new(), drain(..));
99 is_sync_send!(String::new(), drain(..));