diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index e9427fb40a016..4eeee54e11629 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -337,7 +337,9 @@ impl HashSet /// assert_eq!(diff, [4].iter().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn difference<'a>(&'a self, other: &'a HashSet) -> Difference<'a, T, S> { + pub fn difference<'a, U: BuildHasher>(&'a self, + other: &'a HashSet) + -> Difference<'a, T, U> { Difference { iter: self.iter(), other, @@ -391,7 +393,9 @@ impl HashSet /// assert_eq!(intersection, [2, 3].iter().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn intersection<'a>(&'a self, other: &'a HashSet) -> Intersection<'a, T, S> { + pub fn intersection<'a, U: BuildHasher>(&'a self, + other: &'a HashSet) + -> Intersection<'a, T, U> { Intersection { iter: self.iter(), other, @@ -565,7 +569,7 @@ impl HashSet /// assert_eq!(a.is_disjoint(&b), false); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_disjoint(&self, other: &HashSet) -> bool { + pub fn is_disjoint(&self, other: &HashSet) -> bool { self.iter().all(|v| !other.contains(v)) } @@ -587,7 +591,7 @@ impl HashSet /// assert_eq!(set.is_subset(&sup), false); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_subset(&self, other: &HashSet) -> bool { + pub fn is_subset(&self, other: &HashSet) -> bool { self.iter().all(|v| other.contains(v)) } @@ -613,7 +617,7 @@ impl HashSet /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_superset(&self, other: &HashSet) -> bool { + pub fn is_superset(&self, other: &HashSet) -> bool { other.is_subset(self) } @@ -1375,6 +1379,23 @@ fn assert_covariance() { mod test_set { use super::HashSet; use super::super::map::RandomState; + use hash::BuildHasher; + + struct AltRandomState(RandomState); + + impl AltRandomState { + fn new() -> AltRandomState { + AltRandomState(RandomState::new()) + } + } + + impl BuildHasher for AltRandomState { + type Hasher = ::Hasher; + + fn build_hasher(&self) -> Self::Hasher { + self.0.build_hasher() + } + } #[test] fn test_zero_capacities() { @@ -1410,8 +1431,8 @@ mod test_set { #[test] fn test_disjoint() { - let mut xs = HashSet::new(); - let mut ys = HashSet::new(); + let mut xs = HashSet::with_hasher(RandomState::new()); + let mut ys = HashSet::with_hasher(AltRandomState::new()); assert!(xs.is_disjoint(&ys)); assert!(ys.is_disjoint(&xs)); assert!(xs.insert(5)); @@ -1432,13 +1453,13 @@ mod test_set { #[test] fn test_subset_and_superset() { - let mut a = HashSet::new(); + let mut a = HashSet::with_hasher(RandomState::new()); assert!(a.insert(0)); assert!(a.insert(5)); assert!(a.insert(11)); assert!(a.insert(7)); - let mut b = HashSet::new(); + let mut b = HashSet::with_hasher(AltRandomState::new()); assert!(b.insert(0)); assert!(b.insert(7)); assert!(b.insert(19)); @@ -1474,8 +1495,8 @@ mod test_set { #[test] fn test_intersection() { - let mut a = HashSet::new(); - let mut b = HashSet::new(); + let mut a = HashSet::with_hasher(RandomState::new()); + let mut b = HashSet::with_hasher(AltRandomState::new()); assert!(a.insert(11)); assert!(a.insert(1)); @@ -1504,8 +1525,8 @@ mod test_set { #[test] fn test_difference() { - let mut a = HashSet::new(); - let mut b = HashSet::new(); + let mut a = HashSet::with_hasher(RandomState::new()); + let mut b = HashSet::with_hasher(AltRandomState::new()); assert!(a.insert(1)); assert!(a.insert(3));