Skip to content

Commit 9c9725c

Browse files
committed
Remove [T]::array_chunks(_mut)
1 parent d41e12f commit 9c9725c

File tree

7 files changed

+13
-344
lines changed

7 files changed

+13
-344
lines changed

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
// tidy-alphabetical-start
9595
#![feature(alloc_layout_extra)]
9696
#![feature(allocator_api)]
97-
#![feature(array_chunks)]
9897
#![feature(array_into_iter_constructors)]
9998
#![feature(array_windows)]
10099
#![feature(ascii_char)]

library/alloc/src/slice.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use core::cmp::Ordering::{self, Less};
1616
use core::mem::MaybeUninit;
1717
#[cfg(not(no_global_oom_handling))]
1818
use core::ptr;
19-
#[unstable(feature = "array_chunks", issue = "74985")]
20-
pub use core::slice::ArrayChunks;
21-
#[unstable(feature = "array_chunks", issue = "74985")]
22-
pub use core::slice::ArrayChunksMut;
2319
#[unstable(feature = "array_windows", issue = "75027")]
2420
pub use core::slice::ArrayWindows;
2521
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]

library/alloc/src/string.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,12 @@ impl String {
787787
#[cfg(not(no_global_oom_handling))]
788788
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
789789
pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error> {
790-
if v.len() % 2 != 0 {
790+
let (chunks, []) = v.as_chunks::<2>() else {
791791
return Err(FromUtf16Error(()));
792-
}
792+
};
793793
match (cfg!(target_endian = "little"), unsafe { v.align_to::<u16>() }) {
794794
(true, ([], v, [])) => Self::from_utf16(v),
795-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes))
795+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
796796
.collect::<Result<_, _>>()
797797
.map_err(|_| FromUtf16Error(())),
798798
}
@@ -830,11 +830,11 @@ impl String {
830830
(true, ([], v, [])) => Self::from_utf16_lossy(v),
831831
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
832832
_ => {
833-
let mut iter = v.array_chunks::<2>();
834-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_le_bytes))
833+
let (chunks, remainder) = v.as_chunks::<2>();
834+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
835835
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
836836
.collect();
837-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
837+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
838838
}
839839
}
840840
}
@@ -862,12 +862,12 @@ impl String {
862862
#[cfg(not(no_global_oom_handling))]
863863
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
864864
pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error> {
865-
if v.len() % 2 != 0 {
865+
let (chunks, []) = v.as_chunks::<2>() else {
866866
return Err(FromUtf16Error(()));
867-
}
867+
};
868868
match (cfg!(target_endian = "big"), unsafe { v.align_to::<u16>() }) {
869869
(true, ([], v, [])) => Self::from_utf16(v),
870-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_be_bytes))
870+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
871871
.collect::<Result<_, _>>()
872872
.map_err(|_| FromUtf16Error(())),
873873
}
@@ -905,11 +905,11 @@ impl String {
905905
(true, ([], v, [])) => Self::from_utf16_lossy(v),
906906
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
907907
_ => {
908-
let mut iter = v.array_chunks::<2>();
909-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_be_bytes))
908+
let (chunks, remainder) = v.as_chunks::<2>();
909+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
910910
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
911911
.collect();
912-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
912+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
913913
}
914914
}
915915
}

library/core/src/slice/iter.rs

Lines changed: 0 additions & 249 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,255 +2301,6 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
23012301
}
23022302
}
23032303

2304-
/// An iterator over a slice in (non-overlapping) chunks (`N` elements at a
2305-
/// time), starting at the beginning of the slice.
2306-
///
2307-
/// When the slice len is not evenly divided by the chunk size, the last
2308-
/// up to `N-1` elements will be omitted but can be retrieved from
2309-
/// the [`remainder`] function from the iterator.
2310-
///
2311-
/// This struct is created by the [`array_chunks`] method on [slices].
2312-
///
2313-
/// # Example
2314-
///
2315-
/// ```
2316-
/// #![feature(array_chunks)]
2317-
///
2318-
/// let slice = ['l', 'o', 'r', 'e', 'm'];
2319-
/// let mut iter = slice.array_chunks::<2>();
2320-
/// assert_eq!(iter.next(), Some(&['l', 'o']));
2321-
/// assert_eq!(iter.next(), Some(&['r', 'e']));
2322-
/// assert_eq!(iter.next(), None);
2323-
/// ```
2324-
///
2325-
/// [`array_chunks`]: slice::array_chunks
2326-
/// [`remainder`]: ArrayChunks::remainder
2327-
/// [slices]: slice
2328-
#[derive(Debug)]
2329-
#[unstable(feature = "array_chunks", issue = "74985")]
2330-
#[must_use = "iterators are lazy and do nothing unless consumed"]
2331-
pub struct ArrayChunks<'a, T: 'a, const N: usize> {
2332-
iter: Iter<'a, [T; N]>,
2333-
rem: &'a [T],
2334-
}
2335-
2336-
impl<'a, T, const N: usize> ArrayChunks<'a, T, N> {
2337-
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
2338-
#[inline]
2339-
pub(super) const fn new(slice: &'a [T]) -> Self {
2340-
let (array_slice, rem) = slice.as_chunks();
2341-
Self { iter: array_slice.iter(), rem }
2342-
}
2343-
2344-
/// Returns the remainder of the original slice that is not going to be
2345-
/// returned by the iterator. The returned slice has at most `N-1`
2346-
/// elements.
2347-
#[must_use]
2348-
#[unstable(feature = "array_chunks", issue = "74985")]
2349-
pub fn remainder(&self) -> &'a [T] {
2350-
self.rem
2351-
}
2352-
}
2353-
2354-
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
2355-
#[unstable(feature = "array_chunks", issue = "74985")]
2356-
impl<T, const N: usize> Clone for ArrayChunks<'_, T, N> {
2357-
fn clone(&self) -> Self {
2358-
ArrayChunks { iter: self.iter.clone(), rem: self.rem }
2359-
}
2360-
}
2361-
2362-
#[unstable(feature = "array_chunks", issue = "74985")]
2363-
impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> {
2364-
type Item = &'a [T; N];
2365-
2366-
#[inline]
2367-
fn next(&mut self) -> Option<&'a [T; N]> {
2368-
self.iter.next()
2369-
}
2370-
2371-
#[inline]
2372-
fn size_hint(&self) -> (usize, Option<usize>) {
2373-
self.iter.size_hint()
2374-
}
2375-
2376-
#[inline]
2377-
fn count(self) -> usize {
2378-
self.iter.count()
2379-
}
2380-
2381-
#[inline]
2382-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
2383-
self.iter.nth(n)
2384-
}
2385-
2386-
#[inline]
2387-
fn last(self) -> Option<Self::Item> {
2388-
self.iter.last()
2389-
}
2390-
2391-
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a [T; N] {
2392-
// SAFETY: The safety guarantees of `__iterator_get_unchecked` are
2393-
// transferred to the caller.
2394-
unsafe { self.iter.__iterator_get_unchecked(i) }
2395-
}
2396-
}
2397-
2398-
#[unstable(feature = "array_chunks", issue = "74985")]
2399-
impl<'a, T, const N: usize> DoubleEndedIterator for ArrayChunks<'a, T, N> {
2400-
#[inline]
2401-
fn next_back(&mut self) -> Option<&'a [T; N]> {
2402-
self.iter.next_back()
2403-
}
2404-
2405-
#[inline]
2406-
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2407-
self.iter.nth_back(n)
2408-
}
2409-
}
2410-
2411-
#[unstable(feature = "array_chunks", issue = "74985")]
2412-
impl<T, const N: usize> ExactSizeIterator for ArrayChunks<'_, T, N> {
2413-
fn is_empty(&self) -> bool {
2414-
self.iter.is_empty()
2415-
}
2416-
}
2417-
2418-
#[unstable(feature = "trusted_len", issue = "37572")]
2419-
unsafe impl<T, const N: usize> TrustedLen for ArrayChunks<'_, T, N> {}
2420-
2421-
#[unstable(feature = "array_chunks", issue = "74985")]
2422-
impl<T, const N: usize> FusedIterator for ArrayChunks<'_, T, N> {}
2423-
2424-
#[doc(hidden)]
2425-
#[unstable(feature = "array_chunks", issue = "74985")]
2426-
unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunks<'a, T, N> {}
2427-
2428-
#[doc(hidden)]
2429-
#[unstable(feature = "array_chunks", issue = "74985")]
2430-
unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunks<'a, T, N> {
2431-
const MAY_HAVE_SIDE_EFFECT: bool = false;
2432-
}
2433-
2434-
/// An iterator over a slice in (non-overlapping) mutable chunks (`N` elements
2435-
/// at a time), starting at the beginning of the slice.
2436-
///
2437-
/// When the slice len is not evenly divided by the chunk size, the last
2438-
/// up to `N-1` elements will be omitted but can be retrieved from
2439-
/// the [`into_remainder`] function from the iterator.
2440-
///
2441-
/// This struct is created by the [`array_chunks_mut`] method on [slices].
2442-
///
2443-
/// # Example
2444-
///
2445-
/// ```
2446-
/// #![feature(array_chunks)]
2447-
///
2448-
/// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2449-
/// let iter = slice.array_chunks_mut::<2>();
2450-
/// ```
2451-
///
2452-
/// [`array_chunks_mut`]: slice::array_chunks_mut
2453-
/// [`into_remainder`]: ../../std/slice/struct.ArrayChunksMut.html#method.into_remainder
2454-
/// [slices]: slice
2455-
#[derive(Debug)]
2456-
#[unstable(feature = "array_chunks", issue = "74985")]
2457-
#[must_use = "iterators are lazy and do nothing unless consumed"]
2458-
pub struct ArrayChunksMut<'a, T: 'a, const N: usize> {
2459-
iter: IterMut<'a, [T; N]>,
2460-
rem: &'a mut [T],
2461-
}
2462-
2463-
impl<'a, T, const N: usize> ArrayChunksMut<'a, T, N> {
2464-
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
2465-
#[inline]
2466-
pub(super) const fn new(slice: &'a mut [T]) -> Self {
2467-
let (array_slice, rem) = slice.as_chunks_mut();
2468-
Self { iter: array_slice.iter_mut(), rem }
2469-
}
2470-
2471-
/// Returns the remainder of the original slice that is not going to be
2472-
/// returned by the iterator. The returned slice has at most `N-1`
2473-
/// elements.
2474-
#[must_use = "`self` will be dropped if the result is not used"]
2475-
#[unstable(feature = "array_chunks", issue = "74985")]
2476-
pub fn into_remainder(self) -> &'a mut [T] {
2477-
self.rem
2478-
}
2479-
}
2480-
2481-
#[unstable(feature = "array_chunks", issue = "74985")]
2482-
impl<'a, T, const N: usize> Iterator for ArrayChunksMut<'a, T, N> {
2483-
type Item = &'a mut [T; N];
2484-
2485-
#[inline]
2486-
fn next(&mut self) -> Option<&'a mut [T; N]> {
2487-
self.iter.next()
2488-
}
2489-
2490-
#[inline]
2491-
fn size_hint(&self) -> (usize, Option<usize>) {
2492-
self.iter.size_hint()
2493-
}
2494-
2495-
#[inline]
2496-
fn count(self) -> usize {
2497-
self.iter.count()
2498-
}
2499-
2500-
#[inline]
2501-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
2502-
self.iter.nth(n)
2503-
}
2504-
2505-
#[inline]
2506-
fn last(self) -> Option<Self::Item> {
2507-
self.iter.last()
2508-
}
2509-
2510-
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a mut [T; N] {
2511-
// SAFETY: The safety guarantees of `__iterator_get_unchecked` are transferred to
2512-
// the caller.
2513-
unsafe { self.iter.__iterator_get_unchecked(i) }
2514-
}
2515-
}
2516-
2517-
#[unstable(feature = "array_chunks", issue = "74985")]
2518-
impl<'a, T, const N: usize> DoubleEndedIterator for ArrayChunksMut<'a, T, N> {
2519-
#[inline]
2520-
fn next_back(&mut self) -> Option<&'a mut [T; N]> {
2521-
self.iter.next_back()
2522-
}
2523-
2524-
#[inline]
2525-
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2526-
self.iter.nth_back(n)
2527-
}
2528-
}
2529-
2530-
#[unstable(feature = "array_chunks", issue = "74985")]
2531-
impl<T, const N: usize> ExactSizeIterator for ArrayChunksMut<'_, T, N> {
2532-
fn is_empty(&self) -> bool {
2533-
self.iter.is_empty()
2534-
}
2535-
}
2536-
2537-
#[unstable(feature = "trusted_len", issue = "37572")]
2538-
unsafe impl<T, const N: usize> TrustedLen for ArrayChunksMut<'_, T, N> {}
2539-
2540-
#[unstable(feature = "array_chunks", issue = "74985")]
2541-
impl<T, const N: usize> FusedIterator for ArrayChunksMut<'_, T, N> {}
2542-
2543-
#[doc(hidden)]
2544-
#[unstable(feature = "array_chunks", issue = "74985")]
2545-
unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunksMut<'a, T, N> {}
2546-
2547-
#[doc(hidden)]
2548-
#[unstable(feature = "array_chunks", issue = "74985")]
2549-
unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunksMut<'a, T, N> {
2550-
const MAY_HAVE_SIDE_EFFECT: bool = false;
2551-
}
2552-
25532304
/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
25542305
/// time), starting at the end of the slice.
25552306
///

0 commit comments

Comments
 (0)