From 1fec8c28353321048447465506dc68ab3a6c335e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 10 Feb 2019 17:54:56 +0100 Subject: [PATCH] Make the Entry API of HashMap Sync and Send (fixes #45219) --- src/libstd/collections/hash/map.rs | 10 ++++++++++ .../sync-send-iterators-in-libcollections.rs | 1 + 2 files changed, 11 insertions(+) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 91c4e990e007d..8bd87ff9b6c32 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2339,6 +2339,11 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> { elem: FullBucket>, } +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl<'a, K: 'a + Send, V: 'a + Send> Send for OccupiedEntry<'a, K, V> {} +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl<'a, K: 'a + Sync, V: 'a + Sync> Sync for OccupiedEntry<'a, K, V> {} + #[stable(feature= "debug_hash_map", since = "1.12.0")] impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -2360,6 +2365,11 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> { elem: VacantEntryState>, } +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl<'a, K: 'a + Send, V: 'a + Send> Send for VacantEntry<'a, K, V> {} +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl<'a, K: 'a + Sync, V: 'a + Sync> Sync for VacantEntry<'a, K, V> {} + #[stable(feature= "debug_hash_map", since = "1.12.0")] impl<'a, K: 'a + Debug, V: 'a> Debug for VacantEntry<'a, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/test/run-pass/threads-sendsync/sync-send-iterators-in-libcollections.rs b/src/test/run-pass/threads-sendsync/sync-send-iterators-in-libcollections.rs index 812cf89751efd..fd53bb607f79d 100644 --- a/src/test/run-pass/threads-sendsync/sync-send-iterators-in-libcollections.rs +++ b/src/test/run-pass/threads-sendsync/sync-send-iterators-in-libcollections.rs @@ -53,6 +53,7 @@ fn main() { is_sync_send!(BTreeSet::::new(), union(&BTreeSet::::new())); all_sync_send!(HashMap::::new(), iter, iter_mut, drain, into_iter, keys, values); + is_sync_send!(HashMap::::new(), entry(0)); 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()));