Skip to content

Commit d2c223a

Browse files
committed
Auto merge of #26126 - Nashenas88:sync-send-libcore-iter, r=huonw
This addresses an item in #22709. SizeHint in libcore/iter.rs also implements Iterator, but it's implementation is not accessible and is only used to send size hints to extend (it appears to be a performance improvement to avoid unnecessary memory reallocations). The is the only implementation of Iterator within libcore/iter.rs that is not/cannot be tested in this PR.
2 parents aa00f2e + 12dc01d commit d2c223a

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

src/test/run-pass/sync-send-iterators-in-libcore.rs

+76-3
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,101 @@
1010

1111
// pretty-expanded FIXME #23616
1212

13+
#![allow(unused_mut)]
14+
#![feature(core)]
1315
#![feature(collections)]
16+
#![feature(step_by)]
17+
#![feature(iter_empty)]
18+
#![feature(iter_once)]
19+
20+
use std::iter::{empty, once, range_inclusive, repeat, Unfold};
1421

1522
fn is_sync<T>(_: T) where T: Sync {}
1623
fn is_send<T>(_: T) where T: Send {}
1724

1825
macro_rules! all_sync_send {
26+
($ctor:expr, $iter:ident) => ({
27+
let mut x = $ctor;
28+
is_sync(x.$iter());
29+
let mut y = $ctor;
30+
is_send(y.$iter());
31+
});
32+
($ctor:expr, $iter:ident($($param:expr),+)) => ({
33+
let mut x = $ctor;
34+
is_sync(x.$iter($( $param ),+));
35+
let mut y = $ctor;
36+
is_send(y.$iter($( $param ),+));
37+
});
38+
($ctor:expr, $iter:ident, $($rest:tt)*) => ({
39+
all_sync_send!($ctor, $iter);
40+
all_sync_send!($ctor, $($rest)*);
41+
});
42+
($ctor:expr, $iter:ident($($param:expr),+), $($rest:tt)*) => ({
43+
all_sync_send!($ctor, $iter($( $param ),+));
44+
all_sync_send!($ctor, $($rest)*);
45+
});
46+
}
47+
48+
macro_rules! all_sync_send_mutable_ref {
1949
($ctor:expr, $($iter:ident),+) => ({
2050
$(
2151
let mut x = $ctor;
22-
is_sync(x.$iter());
52+
is_sync((&mut x).$iter());
2353
let mut y = $ctor;
24-
is_send(y.$iter());
54+
is_send((&mut y).$iter());
2555
)+
2656
})
2757
}
2858

59+
macro_rules! is_sync_send {
60+
($ctor:expr) => ({
61+
let x = $ctor;
62+
is_sync(x);
63+
let y = $ctor;
64+
is_send(y);
65+
})
66+
}
67+
2968
fn main() {
3069
// for char.rs
3170
all_sync_send!("Я", escape_default, escape_unicode);
3271

3372
// for iter.rs
34-
// FIXME
73+
all_sync_send_mutable_ref!([1], iter);
74+
75+
// Bytes implements DoubleEndedIterator
76+
all_sync_send!("a".bytes(), rev);
77+
78+
let a = [1];
79+
let b = [2];
80+
all_sync_send!(a.iter(),
81+
cloned,
82+
cycle,
83+
chain([2].iter()),
84+
zip([2].iter()),
85+
map(|_| 1),
86+
filter(|_| true),
87+
filter_map(|_| Some(1)),
88+
enumerate,
89+
peekable,
90+
skip_while(|_| true),
91+
take_while(|_| true),
92+
skip(1),
93+
take(1),
94+
scan(1, |_, _| Some(1)),
95+
flat_map(|_| b.iter()),
96+
fuse,
97+
inspect(|_| ()));
98+
99+
is_sync_send!(Unfold::new(Some(1), |&mut v| v));
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));
35108

36109
// for option.rs
37110
// FIXME

0 commit comments

Comments
 (0)