]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/sync-send-iterators-in-libcollections.rs
Rollup merge of #29176 - huonw:shared-tracking, r=Gankro
[rust.git] / src / test / run-pass / sync-send-iterators-in-libcollections.rs
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 // pretty-expanded FIXME #23616
12
13 #![allow(warnings)]
14 #![feature(collections)]
15 #![feature(drain, enumset, collections_bound, btree_range, vecmap)]
16
17 extern crate collections;
18
19 use collections::BinaryHeap;
20 use collections::{BTreeMap, BTreeSet};
21 use collections::EnumSet;
22 use collections::LinkedList;
23 use collections::String;
24 use collections::Vec;
25 use collections::VecDeque;
26 use std::collections::HashMap;
27 use std::collections::HashSet;
28
29 use collections::Bound::Included;
30 use collections::enum_set::CLike;
31 use std::mem;
32
33 fn is_sync<T>(_: T) where T: Sync {}
34 fn is_send<T>(_: T) where T: Send {}
35
36 macro_rules! all_sync_send {
37     ($ctor:expr, $($iter:ident),+) => ({
38         $(
39             let mut x = $ctor;
40             is_sync(x.$iter());
41             let mut y = $ctor;
42             is_send(y.$iter());
43         )+
44     })
45 }
46
47 macro_rules! is_sync_send {
48     ($ctor:expr, $iter:ident($($param:expr),+)) => ({
49         let mut x = $ctor;
50         is_sync(x.$iter($( $param ),+));
51         let mut y = $ctor;
52         is_send(y.$iter($( $param ),+));
53     })
54 }
55
56 fn main() {
57     // The iterator "generator" list should exhaust what corresponding
58     // implementations have where `Sync` and `Send` semantics apply.
59     all_sync_send!(BinaryHeap::<usize>::new(), iter, drain, into_iter);
60
61     all_sync_send!(BTreeMap::<usize, usize>::new(), iter, iter_mut, into_iter, keys, values);
62     is_sync_send!(BTreeMap::<usize, usize>::new(), range(Included(&0), Included(&9)));
63     is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut(Included(&0), Included(&9)));
64
65     all_sync_send!(BTreeSet::<usize>::new(), iter, into_iter);
66     is_sync_send!(BTreeSet::<usize>::new(), range(Included(&0), Included(&9)));
67     is_sync_send!(BTreeSet::<usize>::new(), difference(&BTreeSet::<usize>::new()));
68     is_sync_send!(BTreeSet::<usize>::new(), symmetric_difference(&BTreeSet::<usize>::new()));
69     is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new()));
70     is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new()));
71
72     all_sync_send!(HashMap::<usize, usize>::new(), iter, iter_mut, drain, into_iter, keys, values);
73     all_sync_send!(HashSet::<usize>::new(), iter, drain, into_iter);
74     is_sync_send!(HashSet::<usize>::new(), difference(&HashSet::<usize>::new()));
75     is_sync_send!(HashSet::<usize>::new(), symmetric_difference(&HashSet::<usize>::new()));
76     is_sync_send!(HashSet::<usize>::new(), intersection(&HashSet::<usize>::new()));
77     is_sync_send!(HashSet::<usize>::new(), union(&HashSet::<usize>::new()));
78
79     all_sync_send!(LinkedList::<usize>::new(), iter, iter_mut, into_iter);
80
81     #[derive(Copy, Clone)]
82     #[repr(usize)]
83     #[allow(dead_code)]
84     enum Foo { A, B, C }
85     impl CLike for Foo {
86         fn to_usize(&self) -> usize {
87             *self as usize
88         }
89
90         fn from_usize(v: usize) -> Foo {
91             unsafe { mem::transmute(v) }
92         }
93     }
94     all_sync_send!(EnumSet::<Foo>::new(), iter);
95
96     all_sync_send!(VecDeque::<usize>::new(), iter, iter_mut, into_iter);
97     is_sync_send!(VecDeque::<usize>::new(), drain(..));
98
99     all_sync_send!(Vec::<usize>::new(), into_iter);
100     is_sync_send!(Vec::<usize>::new(), drain(..));
101     is_sync_send!(String::new(), drain(..));
102 }