Skip to content

Commit f2f4a5c

Browse files
Add HashSet and HashMap tests
1 parent a4e4233 commit f2f4a5c

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

src/libstd/collections/hash/set.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use borrow::Borrow;
1212
use clone::Clone;
1313
use cmp::{Eq, PartialEq};
14-
use core::marker::{Sized, Send, Sync};
14+
use core::marker::Sized;
1515
use default::Default;
1616
use fmt::Debug;
1717
use fmt;
@@ -764,27 +764,18 @@ pub struct Iter<'a, K: 'a> {
764764
iter: Keys<'a, K, ()>
765765
}
766766

767-
unsafe impl<'a, K: Send> Send for Iter<'a, K> {}
768-
unsafe impl<'a, K: Sync> Sync for Iter<'a, K> {}
769-
770767
/// HashSet move iterator
771768
#[stable(feature = "rust1", since = "1.0.0")]
772769
pub struct IntoIter<K> {
773770
iter: Map<map::IntoIter<K, ()>, fn((K, ())) -> K>
774771
}
775772

776-
unsafe impl<K: Send> Send for IntoIter<K> {}
777-
unsafe impl<K: Sync> Sync for IntoIter<K> {}
778-
779773
/// HashSet drain iterator
780774
#[stable(feature = "rust1", since = "1.0.0")]
781775
pub struct Drain<'a, K: 'a> {
782776
iter: Map<map::Drain<'a, K, ()>, fn((K, ())) -> K>,
783777
}
784778

785-
unsafe impl<'a, K: Send> Send for Drain<'a, K> {}
786-
unsafe impl<'a, K: Sync> Sync for Drain<'a, K> {}
787-
788779
/// Intersection iterator
789780
#[stable(feature = "rust1", since = "1.0.0")]
790781
pub struct Intersection<'a, T: 'a, S: 'a> {
@@ -794,9 +785,6 @@ pub struct Intersection<'a, T: 'a, S: 'a> {
794785
other: &'a HashSet<T, S>,
795786
}
796787

797-
unsafe impl<'a, K: Send, S: Send> Send for Intersection<'a, K, S> {}
798-
unsafe impl<'a, K: Sync, S: Send> Sync for Intersection<'a, K, S> {}
799-
800788
/// Difference iterator
801789
#[stable(feature = "rust1", since = "1.0.0")]
802790
pub struct Difference<'a, T: 'a, S: 'a> {
@@ -806,27 +794,18 @@ pub struct Difference<'a, T: 'a, S: 'a> {
806794
other: &'a HashSet<T, S>,
807795
}
808796

809-
unsafe impl<'a, K: Send, S: Send> Send for Difference<'a, K, S> {}
810-
unsafe impl<'a, K: Sync, S: Send> Sync for Difference<'a, K, S> {}
811-
812797
/// Symmetric difference iterator.
813798
#[stable(feature = "rust1", since = "1.0.0")]
814799
pub struct SymmetricDifference<'a, T: 'a, S: 'a> {
815800
iter: Chain<Difference<'a, T, S>, Difference<'a, T, S>>
816801
}
817802

818-
unsafe impl<'a, K: Send, S: Send> Send for SymmetricDifference<'a, K, S> {}
819-
unsafe impl<'a, K: Sync, S: Send> Sync for SymmetricDifference<'a, K, S> {}
820-
821803
/// Set union iterator.
822804
#[stable(feature = "rust1", since = "1.0.0")]
823805
pub struct Union<'a, T: 'a, S: 'a> {
824806
iter: Chain<Iter<'a, T>, Difference<'a, T, S>>
825807
}
826808

827-
unsafe impl<'a, K: Send, S: Send> Send for Union<'a, K, S> {}
828-
unsafe impl<'a, K: Sync, S: Send> Sync for Union<'a, K, S> {}
829-
830809
#[stable(feature = "rust1", since = "1.0.0")]
831810
impl<'a, T, S> IntoIterator for &'a HashSet<T, S>
832811
where T: Eq + Hash, S: HashState

src/libstd/collections/hash/table.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,6 @@ struct RawBuckets<'a, K, V> {
741741
marker: marker::PhantomData<&'a ()>,
742742
}
743743

744-
unsafe impl<'a, K: Send, V: Send> Send for RawBuckets<'a, K, V> {}
745-
unsafe impl<'a, K: Sync, V: Sync> Sync for RawBuckets<'a, K, V> {}
746-
747744
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
748745
impl<'a, K, V> Clone for RawBuckets<'a, K, V> {
749746
fn clone(&self) -> RawBuckets<'a, K, V> {
@@ -821,6 +818,9 @@ pub struct Iter<'a, K: 'a, V: 'a> {
821818
elems_left: usize,
822819
}
823820

821+
unsafe impl<'a, K: Sync, V: Sync> Sync for Iter<'a, K, V> {}
822+
unsafe impl<'a, K: Sync, V: Sync> Send for Iter<'a, K, V> {}
823+
824824
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
825825
impl<'a, K, V> Clone for Iter<'a, K, V> {
826826
fn clone(&self) -> Iter<'a, K, V> {
@@ -838,18 +838,29 @@ pub struct IterMut<'a, K: 'a, V: 'a> {
838838
elems_left: usize,
839839
}
840840

841+
unsafe impl<'a, K: Sync, V: Sync> Sync for IterMut<'a, K, V> {}
842+
// Both K: Sync and K: Send are correct for IterMut's Send impl,
843+
// but Send is the more useful bound
844+
unsafe impl<'a, K: Send, V: Send> Send for IterMut<'a, K, V> {}
845+
841846
/// Iterator over the entries in a table, consuming the table.
842847
pub struct IntoIter<K, V> {
843848
table: RawTable<K, V>,
844849
iter: RawBuckets<'static, K, V>
845850
}
846851

852+
unsafe impl<K: Sync, V: Sync> Sync for IntoIter<K, V> {}
853+
unsafe impl<K: Send, V: Send> Send for IntoIter<K, V> {}
854+
847855
/// Iterator over the entries in a table, clearing the table.
848856
pub struct Drain<'a, K: 'a, V: 'a> {
849857
table: &'a mut RawTable<K, V>,
850858
iter: RawBuckets<'static, K, V>,
851859
}
852860

861+
unsafe impl<'a, K: Sync, V: Sync> Sync for Drain<'a, K, V> {}
862+
unsafe impl<'a, K: Send, V: Send> Send for Drain<'a, K, V> {}
863+
853864
impl<'a, K, V> Iterator for Iter<'a, K, V> {
854865
type Item = (&'a K, &'a V);
855866

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use collections::Vec;
2626
use collections::VecDeque;
2727
use collections::VecMap;
2828
use std::collections::HashMap;
29+
use std::collections::HashSet;
2930

3031
use collections::Bound::Included;
3132
use collections::enum_set::CLike;
@@ -78,7 +79,12 @@ fn main() {
7879
is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new()));
7980
is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new()));
8081

81-
all_sync_send!(HashMap::<usize, usize>::new(), keys, values, iter, iter_mut);
82+
all_sync_send!(HashMap::<usize, usize>::new(), iter, iter_mut, drain, into_iter, keys, values);
83+
all_sync_send!(HashSet::<usize>::new(), iter, drain, into_iter);
84+
is_sync_send!(HashSet::<usize>::new(), difference(&HashSet::<usize>::new()));
85+
is_sync_send!(HashSet::<usize>::new(), symmetric_difference(&HashSet::<usize>::new()));
86+
is_sync_send!(HashSet::<usize>::new(), intersection(&HashSet::<usize>::new()));
87+
is_sync_send!(HashSet::<usize>::new(), union(&HashSet::<usize>::new()));
8288

8389
all_sync_send!(LinkedList::<usize>::new(), iter, iter_mut, into_iter);
8490

0 commit comments

Comments
 (0)