Skip to content

Commit c3fe710

Browse files
author
Jorge Aparicio
committed
libstd: fix fallout
1 parent 4f6f6af commit c3fe710

File tree

1 file changed

+22
-14
lines changed
  • src/libstd/collections/hash

1 file changed

+22
-14
lines changed

src/libstd/collections/hash/set.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use fmt;
1919
use hash::{Hash, Hasher, RandomSipHasher};
2020
use iter::{Iterator, IteratorExt, FromIterator, FilterMap, Chain, Repeat, Zip, Extend, repeat};
2121
use iter;
22-
use option::Option::{Some, None};
22+
use option::Option::{Some, None, mod};
2323
use result::Result::{Ok, Err};
2424

2525
use super::map::{HashMap, Entries, MoveEntries, INITIAL_CAPACITY};
@@ -306,10 +306,13 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
306306
/// ```
307307
#[unstable = "matches collection reform specification, waiting for dust to settle"]
308308
pub fn difference<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H> {
309-
repeat(other).zip(self.iter())
310-
.filter_map(|(other, elt)| {
311-
if !other.contains(elt) { Some(elt) } else { None }
312-
})
309+
fn filter<'a, T, S, H>((other, elt): (&HashSet<T, H>, &'a T)) -> Option<&'a T> where
310+
T: Eq + Hash<S>, H: Hasher<S>
311+
{
312+
if !other.contains(elt) { Some(elt) } else { None }
313+
}
314+
315+
repeat(other).zip(self.iter()).filter_map(filter)
313316
}
314317

315318
/// Visit the values representing the symmetric difference.
@@ -356,12 +359,14 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
356359
/// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect());
357360
/// ```
358361
#[unstable = "matches collection reform specification, waiting for dust to settle"]
359-
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, H>)
360-
-> SetAlgebraItems<'a, T, H> {
361-
repeat(other).zip(self.iter())
362-
.filter_map(|(other, elt)| {
363-
if other.contains(elt) { Some(elt) } else { None }
364-
})
362+
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H> {
363+
fn filter<'a, T, S, H>((other, elt): (&HashSet<T, H>, &'a T)) -> Option<&'a T> where
364+
T: Eq + Hash<S>, H: Hasher<S>
365+
{
366+
if other.contains(elt) { Some(elt) } else { None }
367+
}
368+
369+
repeat(other).zip(self.iter()).filter_map(filter)
365370
}
366371

367372
/// Visit the values representing the union.
@@ -621,9 +626,12 @@ pub type SetMoveItems<K> = iter::Map<(K, ()), K, MoveEntries<K, ()>, fn((K, ()))
621626
// `Repeat` is used to feed the filter closure an explicit capture
622627
// of a reference to the other set
623628
/// Set operations iterator
624-
pub type SetAlgebraItems<'a, T, H> =
625-
FilterMap<'static, (&'a HashSet<T, H>, &'a T), &'a T,
626-
Zip<Repeat<&'a HashSet<T, H>>, SetItems<'a, T>>>;
629+
pub type SetAlgebraItems<'a, T, H> = FilterMap<
630+
(&'a HashSet<T, H>, &'a T),
631+
&'a T,
632+
Zip<Repeat<&'a HashSet<T, H>>, SetItems<'a, T>>,
633+
for<'b> fn((&HashSet<T, H>, &'b T)) -> Option<&'b T>,
634+
>;
627635

628636
#[cfg(test)]
629637
mod test_set {

0 commit comments

Comments
 (0)