diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 445391bbe3a1020fcc454877f9bced6b3f9297e4..fb594dadd738be984f61bee7f4cce4b0545644e1 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -11,7 +11,7 @@ use borrow::Borrow; use clone::Clone; use cmp::{Eq, PartialEq}; -use core::marker::{Sized, Send, Sync}; +use core::marker::Sized; use default::Default; use fmt::Debug; use fmt; @@ -764,27 +764,18 @@ pub struct Iter<'a, K: 'a> { iter: Keys<'a, K, ()> } -unsafe impl<'a, K: Send> Send for Iter<'a, K> {} -unsafe impl<'a, K: Sync> Sync for Iter<'a, K> {} - /// HashSet move iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { iter: Map, fn((K, ())) -> K> } -unsafe impl Send for IntoIter {} -unsafe impl Sync for IntoIter {} - /// HashSet drain iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct Drain<'a, K: 'a> { iter: Map, fn((K, ())) -> K>, } -unsafe impl<'a, K: Send> Send for Drain<'a, K> {} -unsafe impl<'a, K: Sync> Sync for Drain<'a, K> {} - /// Intersection iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct Intersection<'a, T: 'a, S: 'a> { @@ -794,9 +785,6 @@ pub struct Intersection<'a, T: 'a, S: 'a> { other: &'a HashSet, } -unsafe impl<'a, K: Send, S: Send> Send for Intersection<'a, K, S> {} -unsafe impl<'a, K: Sync, S: Send> Sync for Intersection<'a, K, S> {} - /// Difference iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct Difference<'a, T: 'a, S: 'a> { @@ -806,27 +794,18 @@ pub struct Difference<'a, T: 'a, S: 'a> { other: &'a HashSet, } -unsafe impl<'a, K: Send, S: Send> Send for Difference<'a, K, S> {} -unsafe impl<'a, K: Sync, S: Send> Sync for Difference<'a, K, S> {} - /// Symmetric difference iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct SymmetricDifference<'a, T: 'a, S: 'a> { iter: Chain, Difference<'a, T, S>> } -unsafe impl<'a, K: Send, S: Send> Send for SymmetricDifference<'a, K, S> {} -unsafe impl<'a, K: Sync, S: Send> Sync for SymmetricDifference<'a, K, S> {} - /// Set union iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Union<'a, T: 'a, S: 'a> { iter: Chain, Difference<'a, T, S>> } -unsafe impl<'a, K: Send, S: Send> Send for Union<'a, K, S> {} -unsafe impl<'a, K: Sync, S: Send> Sync for Union<'a, K, S> {} - #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S> IntoIterator for &'a HashSet where T: Eq + Hash, S: HashState diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index ee63e29e6c9a47a88a2cb921a9d2cd2cf090f736..8a822057bbff7f037bed645f334bdf4a076e40ae 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -741,9 +741,6 @@ struct RawBuckets<'a, K, V> { marker: marker::PhantomData<&'a ()>, } -unsafe impl<'a, K: Send, V: Send> Send for RawBuckets<'a, K, V> {} -unsafe impl<'a, K: Sync, V: Sync> Sync for RawBuckets<'a, K, V> {} - // FIXME(#19839) Remove in favor of `#[derive(Clone)]` impl<'a, K, V> Clone for RawBuckets<'a, K, V> { fn clone(&self) -> RawBuckets<'a, K, V> { @@ -821,6 +818,9 @@ pub struct Iter<'a, K: 'a, V: 'a> { elems_left: usize, } +unsafe impl<'a, K: Sync, V: Sync> Sync for Iter<'a, K, V> {} +unsafe impl<'a, K: Sync, V: Sync> Send for Iter<'a, K, V> {} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` impl<'a, K, V> Clone for Iter<'a, K, V> { fn clone(&self) -> Iter<'a, K, V> { @@ -838,18 +838,29 @@ pub struct IterMut<'a, K: 'a, V: 'a> { elems_left: usize, } +unsafe impl<'a, K: Sync, V: Sync> Sync for IterMut<'a, K, V> {} +// Both K: Sync and K: Send are correct for IterMut's Send impl, +// but Send is the more useful bound +unsafe impl<'a, K: Send, V: Send> Send for IterMut<'a, K, V> {} + /// Iterator over the entries in a table, consuming the table. pub struct IntoIter { table: RawTable, iter: RawBuckets<'static, K, V> } +unsafe impl Sync for IntoIter {} +unsafe impl Send for IntoIter {} + /// Iterator over the entries in a table, clearing the table. pub struct Drain<'a, K: 'a, V: 'a> { table: &'a mut RawTable, iter: RawBuckets<'static, K, V>, } +unsafe impl<'a, K: Sync, V: Sync> Sync for Drain<'a, K, V> {} +unsafe impl<'a, K: Send, V: Send> Send for Drain<'a, K, V> {} + impl<'a, K, V> Iterator for Iter<'a, K, V> { type Item = (&'a K, &'a V); diff --git a/src/test/run-pass/sync-send-iterators-in-libcollections.rs b/src/test/run-pass/sync-send-iterators-in-libcollections.rs index ffa5c611777804dae99454c7bebb25ede26a6e60..cdfc4d32027bb1220f96e5a1d9a13fc2d7675411 100644 --- a/src/test/run-pass/sync-send-iterators-in-libcollections.rs +++ b/src/test/run-pass/sync-send-iterators-in-libcollections.rs @@ -26,6 +26,7 @@ use collections::VecDeque; use collections::VecMap; use std::collections::HashMap; +use std::collections::HashSet; use collections::Bound::Included; use collections::enum_set::CLike; @@ -78,7 +79,12 @@ fn main() { is_sync_send!(BTreeSet::::new(), intersection(&BTreeSet::::new())); is_sync_send!(BTreeSet::::new(), union(&BTreeSet::::new())); - all_sync_send!(HashMap::::new(), keys, values, iter, iter_mut); + all_sync_send!(HashMap::::new(), iter, iter_mut, drain, into_iter, keys, values); + all_sync_send!(HashSet::::new(), iter, drain, into_iter); + is_sync_send!(HashSet::::new(), difference(&HashSet::::new())); + is_sync_send!(HashSet::::new(), symmetric_difference(&HashSet::::new())); + is_sync_send!(HashSet::::new(), intersection(&HashSet::::new())); + is_sync_send!(HashSet::::new(), union(&HashSet::::new())); all_sync_send!(LinkedList::::new(), iter, iter_mut, into_iter);