Skip to content

Commit dce6734

Browse files
committed
Switched to local functions away from closures, per rust-lang#62429
1 parent 9c7fe03 commit dce6734

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/libcore/iter/traits/iterator.rs

+32-17
Original file line numberDiff line numberDiff line change
@@ -1504,27 +1504,36 @@ pub trait Iterator {
15041504
/// assert_eq!(odd, vec![1, 3]);
15051505
/// ```
15061506
#[stable(feature = "rust1", since = "1.0.0")]
1507-
fn partition<B, F>(self, mut predicate: F) -> (B, B) where
1507+
fn partition<B, F>(self, predicate: F) -> (B, B)
1508+
where
15081509
Self: Sized,
15091510
B: Default + Extend<Self::Item>,
1510-
F: FnMut(&Self::Item) -> bool
1511+
F: FnMut(&Self::Item) -> bool,
15111512
{
15121513
let mut left: B = Default::default();
15131514
let mut right: B = Default::default();
1514-
let right_ref = &mut right;
15151515

1516-
left.extend(self.filter_map(#[inline] move |item| {
1517-
if predicate(&item) {
1518-
Some(item)
1519-
} else {
1520-
right_ref.extend(Some(item));
1521-
None
1516+
#[inline]
1517+
fn extend_rhs<'a, A, T: Extend<A>, P: FnMut(&A) -> bool + 'a>(
1518+
rhs: &'a mut T,
1519+
mut predicate: P,
1520+
) -> impl FnMut(A) -> Option<A> + 'a {
1521+
move |item| {
1522+
if predicate(&item) {
1523+
Some(item)
1524+
} else {
1525+
rhs.extend(Some(item));
1526+
None
1527+
}
15221528
}
1523-
}));
1529+
}
1530+
1531+
left.extend(self.filter_map(extend_rhs(&mut right, predicate)));
15241532

15251533
(left, right)
15261534
}
15271535

1536+
15281537
/// Reorder the elements of this iterator *in-place* according to the given predicate,
15291538
/// such that all those that return `true` precede all those that return `false`.
15301539
/// Returns the number of `true` elements found.
@@ -2366,23 +2375,29 @@ pub trait Iterator {
23662375
/// assert_eq!(right, [2, 4]);
23672376
/// ```
23682377
#[stable(feature = "rust1", since = "1.0.0")]
2369-
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where
2378+
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
2379+
where
23702380
FromA: Default + Extend<A>,
23712381
FromB: Default + Extend<B>,
2372-
Self: Sized + Iterator<Item=(A, B)>,
2382+
Self: Sized + Iterator<Item = (A, B)>,
23732383
{
23742384
let mut lhs = FromA::default();
23752385
let mut rhs = FromB::default();
2376-
let rhs_ref = &mut rhs;
23772386

2378-
lhs.extend(self.map(#[inline] move |(a, b)| {
2379-
rhs_ref.extend(Some(b));
2380-
a
2381-
}));
2387+
#[inline]
2388+
fn extend_rhs<'a, A, B, T: Extend<B>>(rhs: &'a mut T) -> impl FnMut((A, B)) -> A + 'a {
2389+
move |(a, b)| {
2390+
rhs.extend(Some(b));
2391+
a
2392+
}
2393+
}
2394+
2395+
lhs.extend(self.map(extend_rhs(&mut rhs)));
23822396

23832397
(lhs, rhs)
23842398
}
23852399

2400+
23862401
/// Creates an iterator which copies all of its elements.
23872402
///
23882403
/// This is useful when you have an iterator over `&T`, but you need an

0 commit comments

Comments
 (0)