Skip to content

Commit

Permalink
Auto merge of rust-lang#100023 - saethlin:send-sync-chunksmut, r=m-ou-se
Browse files Browse the repository at this point in the history
Add back Send and Sync impls on ChunksMut iterators

Fixes rust-lang#100014

These were accidentally removed in rust-lang#94247 because the representation was changed from `&mut [T]` to `*mut T`, which has `!Send + !Sync`.
  • Loading branch information
bors committed Aug 3, 2022
2 parents 7308c22 + 22dfbdd commit 04f72f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
const MAY_HAVE_SIDE_EFFECT: bool = false;
}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T> Send for ChunksMut<'_, T> where T: Send {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T> Sync for ChunksMut<'_, T> where T: Sync {}

/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
/// time), starting at the beginning of the slice.
///
Expand Down Expand Up @@ -2114,6 +2120,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
const MAY_HAVE_SIDE_EFFECT: bool = false;
}

#[stable(feature = "chunks_exact", since = "1.31.0")]
unsafe impl<T> Send for ChunksExactMut<'_, T> where T: Send {}

#[stable(feature = "chunks_exact", since = "1.31.0")]
unsafe impl<T> Sync for ChunksExactMut<'_, T> where T: Sync {}

/// A windowed iterator over a slice in overlapping chunks (`N` elements at a
/// time), starting at the beginning of the slice
///
Expand Down Expand Up @@ -2835,6 +2847,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
const MAY_HAVE_SIDE_EFFECT: bool = false;
}

#[stable(feature = "rchunks", since = "1.31.0")]
unsafe impl<T> Send for RChunksMut<'_, T> where T: Send {}

#[stable(feature = "rchunks", since = "1.31.0")]
unsafe impl<T> Sync for RChunksMut<'_, T> where T: Sync {}

/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
/// time), starting at the end of the slice.
///
Expand Down Expand Up @@ -3168,6 +3186,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExactMut<'a, T> {
const MAY_HAVE_SIDE_EFFECT: bool = false;
}

#[stable(feature = "rchunks", since = "1.31.0")]
unsafe impl<T> Send for RChunksExactMut<'_, T> where T: Send {}

#[stable(feature = "rchunks", since = "1.31.0")]
unsafe impl<T> Sync for RChunksExactMut<'_, T> where T: Sync {}

#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> {}
Expand Down
21 changes: 21 additions & 0 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,27 @@ fn test_rchunks_exact_mut_zip() {
assert_eq!(v1, [0, 16, 17, 22, 23]);
}

#[test]
fn chunks_mut_are_send_and_sync() {
use std::cell::Cell;
use std::slice::{ChunksExactMut, ChunksMut, RChunksExactMut, RChunksMut};
use std::sync::MutexGuard;

#[allow(unused)]
fn assert_send_and_sync()
where
ChunksMut<'static, Cell<i32>>: Send,
ChunksMut<'static, MutexGuard<'static, u32>>: Sync,
ChunksExactMut<'static, Cell<i32>>: Send,
ChunksExactMut<'static, MutexGuard<'static, u32>>: Sync,
RChunksMut<'static, Cell<i32>>: Send,
RChunksMut<'static, MutexGuard<'static, u32>>: Sync,
RChunksExactMut<'static, Cell<i32>>: Send,
RChunksExactMut<'static, MutexGuard<'static, u32>>: Sync,
{
}
}

#[test]
fn test_windows_count() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
Expand Down

0 comments on commit 04f72f9

Please sign in to comment.