Skip to content

Commit 224287b

Browse files
committed
Reduce the genericity of WhileSomeFolder::consume_iter's closure
The `take_while` closure only needs to be generic in `T`, along with a captured `&AtomicBool`. When we write the closure directly, it carries all the type baggage of `WhileSomeFolder<'f, C>::consumer_iter<I>`, where the monomorphized type may explode. Instead, we can move this closure to a standalone function for reduced genericity.
1 parent 8d2e048 commit 224287b

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/iter/while_some.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ where
126126
where
127127
I: IntoIterator<Item = Option<T>>,
128128
{
129-
let full = self.full;
129+
fn some<T>(full: &AtomicBool) -> impl Fn(&Option<T>) -> bool + '_ {
130+
move |x| match *x {
131+
Some(_) => !full.load(Ordering::Relaxed),
132+
None => {
133+
full.store(true, Ordering::Relaxed);
134+
false
135+
}
136+
}
137+
}
138+
130139
self.base = self.base.consume_iter(
131140
iter.into_iter()
132-
.take_while(|x| match *x {
133-
Some(_) => !full.load(Ordering::Relaxed),
134-
None => {
135-
full.store(true, Ordering::Relaxed);
136-
false
137-
}
138-
})
141+
.take_while(some(self.full))
139142
.map(Option::unwrap),
140143
);
141144
self

tests/issue671.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extern crate rayon;
2+
3+
use rayon::prelude::*;
4+
5+
#[test]
6+
fn type_length_limit() {
7+
let _ = Vec::<Result<(), ()>>::new()
8+
.into_par_iter()
9+
.map(|x| x)
10+
.map(|x| x)
11+
.map(|x| x)
12+
.map(|x| x)
13+
.map(|x| x)
14+
.map(|x| x)
15+
.collect::<Result<(), ()>>();
16+
}

0 commit comments

Comments
 (0)