Skip to content

Commit 04f72f9

Browse files
committed
Auto merge of rust-lang#100023 - saethlin:send-sync-chunksmut, r=m-ou-se
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`.
2 parents 7308c22 + 22dfbdd commit 04f72f9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

library/core/src/slice/iter.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
17881788
const MAY_HAVE_SIDE_EFFECT: bool = false;
17891789
}
17901790

1791+
#[stable(feature = "rust1", since = "1.0.0")]
1792+
unsafe impl<T> Send for ChunksMut<'_, T> where T: Send {}
1793+
1794+
#[stable(feature = "rust1", since = "1.0.0")]
1795+
unsafe impl<T> Sync for ChunksMut<'_, T> where T: Sync {}
1796+
17911797
/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
17921798
/// time), starting at the beginning of the slice.
17931799
///
@@ -2114,6 +2120,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
21142120
const MAY_HAVE_SIDE_EFFECT: bool = false;
21152121
}
21162122

2123+
#[stable(feature = "chunks_exact", since = "1.31.0")]
2124+
unsafe impl<T> Send for ChunksExactMut<'_, T> where T: Send {}
2125+
2126+
#[stable(feature = "chunks_exact", since = "1.31.0")]
2127+
unsafe impl<T> Sync for ChunksExactMut<'_, T> where T: Sync {}
2128+
21172129
/// A windowed iterator over a slice in overlapping chunks (`N` elements at a
21182130
/// time), starting at the beginning of the slice
21192131
///
@@ -2835,6 +2847,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
28352847
const MAY_HAVE_SIDE_EFFECT: bool = false;
28362848
}
28372849

2850+
#[stable(feature = "rchunks", since = "1.31.0")]
2851+
unsafe impl<T> Send for RChunksMut<'_, T> where T: Send {}
2852+
2853+
#[stable(feature = "rchunks", since = "1.31.0")]
2854+
unsafe impl<T> Sync for RChunksMut<'_, T> where T: Sync {}
2855+
28382856
/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
28392857
/// time), starting at the end of the slice.
28402858
///
@@ -3168,6 +3186,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExactMut<'a, T> {
31683186
const MAY_HAVE_SIDE_EFFECT: bool = false;
31693187
}
31703188

3189+
#[stable(feature = "rchunks", since = "1.31.0")]
3190+
unsafe impl<T> Send for RChunksExactMut<'_, T> where T: Send {}
3191+
3192+
#[stable(feature = "rchunks", since = "1.31.0")]
3193+
unsafe impl<T> Sync for RChunksExactMut<'_, T> where T: Sync {}
3194+
31713195
#[doc(hidden)]
31723196
#[unstable(feature = "trusted_random_access", issue = "none")]
31733197
unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> {}

library/core/tests/slice.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,27 @@ fn test_rchunks_exact_mut_zip() {
11911191
assert_eq!(v1, [0, 16, 17, 22, 23]);
11921192
}
11931193

1194+
#[test]
1195+
fn chunks_mut_are_send_and_sync() {
1196+
use std::cell::Cell;
1197+
use std::slice::{ChunksExactMut, ChunksMut, RChunksExactMut, RChunksMut};
1198+
use std::sync::MutexGuard;
1199+
1200+
#[allow(unused)]
1201+
fn assert_send_and_sync()
1202+
where
1203+
ChunksMut<'static, Cell<i32>>: Send,
1204+
ChunksMut<'static, MutexGuard<'static, u32>>: Sync,
1205+
ChunksExactMut<'static, Cell<i32>>: Send,
1206+
ChunksExactMut<'static, MutexGuard<'static, u32>>: Sync,
1207+
RChunksMut<'static, Cell<i32>>: Send,
1208+
RChunksMut<'static, MutexGuard<'static, u32>>: Sync,
1209+
RChunksExactMut<'static, Cell<i32>>: Send,
1210+
RChunksExactMut<'static, MutexGuard<'static, u32>>: Sync,
1211+
{
1212+
}
1213+
}
1214+
11941215
#[test]
11951216
fn test_windows_count() {
11961217
let v: &[i32] = &[0, 1, 2, 3, 4, 5];

0 commit comments

Comments
 (0)