Skip to content

Commit

Permalink
Rollup merge of rust-lang#58369 - nox:sync-hash-map-entry, r=Amanieu
Browse files Browse the repository at this point in the history
Make the Entry API of HashMap<K, V> Sync and Send

Fixes rust-lang#45219
  • Loading branch information
pietroalbini authored Mar 8, 2019
2 parents bf7b502 + 1fec8c2 commit 55dc386
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,11 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
elem: FullBucket<K, V, &'a mut RawTable<K, V>>,
}

#[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<K: Debug, V: Debug> Debug for OccupiedEntry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -2362,6 +2367,11 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {
elem: VacantEntryState<K, V, &'a mut RawTable<K, V>>,
}

#[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<K: Debug, V> Debug for VacantEntry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn main() {
is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new()));

all_sync_send!(HashMap::<usize, usize>::new(), iter, iter_mut, drain, into_iter, keys, values);
is_sync_send!(HashMap::<usize, usize>::new(), entry(0));
all_sync_send!(HashSet::<usize>::new(), iter, drain, into_iter);
is_sync_send!(HashSet::<usize>::new(), difference(&HashSet::<usize>::new()));
is_sync_send!(HashSet::<usize>::new(), symmetric_difference(&HashSet::<usize>::new()));
Expand Down

0 comments on commit 55dc386

Please sign in to comment.