]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/sync-send-iterators-in-libcore.rs
Auto merge of #27273 - tshepang:claim-not-accurate, r=steveklabnik
[rust.git] / src / test / run-pass / sync-send-iterators-in-libcore.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(iter_empty)]
15 #![feature(iter_once)]
16 #![feature(iter_unfold)]
17 #![feature(range_inclusive)]
18 #![feature(step_by)]
19 #![feature(str_escape)]
20
21 use std::iter::{empty, once, range_inclusive, repeat};
22
23 fn is_sync<T>(_: T) where T: Sync {}
24 fn is_send<T>(_: T) where T: Send {}
25
26 macro_rules! all_sync_send {
27     ($ctor:expr, $iter:ident) => ({
28         let mut x = $ctor;
29         is_sync(x.$iter());
30         let mut y = $ctor;
31         is_send(y.$iter());
32     });
33     ($ctor:expr, $iter:ident($($param:expr),+)) => ({
34         let mut x = $ctor;
35         is_sync(x.$iter($( $param ),+));
36         let mut y = $ctor;
37         is_send(y.$iter($( $param ),+));
38     });
39     ($ctor:expr, $iter:ident, $($rest:tt)*) => ({
40         all_sync_send!($ctor, $iter);
41         all_sync_send!($ctor, $($rest)*);
42     });
43     ($ctor:expr, $iter:ident($($param:expr),+), $($rest:tt)*) => ({
44         all_sync_send!($ctor, $iter($( $param ),+));
45         all_sync_send!($ctor, $($rest)*);
46     });
47 }
48
49 macro_rules! all_sync_send_mutable_ref {
50     ($ctor:expr, $($iter:ident),+) => ({
51         $(
52             let mut x = $ctor;
53             is_sync((&mut x).$iter());
54             let mut y = $ctor;
55             is_send((&mut y).$iter());
56         )+
57     })
58 }
59
60 macro_rules! is_sync_send {
61     ($ctor:expr) => ({
62         let x = $ctor;
63         is_sync(x);
64         let y = $ctor;
65         is_send(y);
66     })
67 }
68
69 fn main() {
70     // for char.rs
71     all_sync_send!("Я", escape_default, escape_unicode);
72
73     // for iter.rs
74     all_sync_send_mutable_ref!([1], iter);
75
76     // Bytes implements DoubleEndedIterator
77     all_sync_send!("a".bytes(), rev);
78
79     let a = [1];
80     let b = [2];
81     all_sync_send!(a.iter(),
82                    cloned,
83                    cycle,
84                    chain([2].iter()),
85                    zip([2].iter()),
86                    map(|_| 1),
87                    filter(|_| true),
88                    filter_map(|_| Some(1)),
89                    enumerate,
90                    peekable,
91                    skip_while(|_| true),
92                    take_while(|_| true),
93                    skip(1),
94                    take(1),
95                    scan(1, |_, _| Some(1)),
96                    flat_map(|_| b.iter()),
97                    fuse,
98                    inspect(|_| ()));
99
100     is_sync_send!((1..).step_by(2));
101     is_sync_send!(range_inclusive(1, 1));
102     is_sync_send!((1..2).step_by(2));
103     is_sync_send!((1..2));
104     is_sync_send!((1..));
105     is_sync_send!(repeat(1));
106     is_sync_send!(empty::<usize>());
107     is_sync_send!(once(1));
108
109     // for option.rs
110     // FIXME
111
112     // for result.rs
113     // FIXME
114
115     // for slice.rs
116     // FIXME
117
118     // for str/mod.rs
119     // FIXME
120 }