Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac39d3c

Browse files
committedNov 7, 2023
Stabilize slice_group_by
Renamed "group by" to "chunk by" a per rust-lang#80552. Newly stable items: * `core::slice::ChunkBy` * `core::slice::ChunkByMut` * `[T]::chunk` * `[T]::chunk_by` Closes rust-lang#80552.
1 parent 187d1af commit ac39d3c

File tree

7 files changed

+54
-65
lines changed

7 files changed

+54
-65
lines changed
 

‎library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
#![feature(set_ptr_value)]
149149
#![feature(sized_type_properties)]
150150
#![feature(slice_from_ptr_range)]
151-
#![feature(slice_group_by)]
152151
#![feature(slice_ptr_get)]
153152
#![feature(slice_ptr_len)]
154153
#![feature(slice_range)]

‎library/alloc/src/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ pub use core::slice::{from_mut, from_ref};
5151
pub use core::slice::{from_mut_ptr_range, from_ptr_range};
5252
#[stable(feature = "rust1", since = "1.0.0")]
5353
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
54+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
55+
pub use core::slice::{ChunkBy, ChunkByMut};
5456
#[stable(feature = "rust1", since = "1.0.0")]
5557
pub use core::slice::{Chunks, Windows};
5658
#[stable(feature = "chunks_exact", since = "1.31.0")]
5759
pub use core::slice::{ChunksExact, ChunksExactMut};
5860
#[stable(feature = "rust1", since = "1.0.0")]
5961
pub use core::slice::{ChunksMut, Split, SplitMut};
60-
#[unstable(feature = "slice_group_by", issue = "80552")]
61-
pub use core::slice::{GroupBy, GroupByMut};
6262
#[stable(feature = "rust1", since = "1.0.0")]
6363
pub use core::slice::{Iter, IterMut};
6464
#[stable(feature = "rchunks", since = "1.31.0")]

‎library/alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(iter_advance_by)]
2929
#![feature(iter_next_chunk)]
3030
#![feature(round_char_boundary)]
31-
#![feature(slice_group_by)]
3231
#![feature(slice_partition_dedup)]
3332
#![feature(string_remove_matches)]
3433
#![feature(const_btree_len)]

‎library/alloc/tests/slice.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1614,26 +1614,26 @@ fn subslice_patterns() {
16141614
}
16151615

16161616
#[test]
1617-
fn test_group_by() {
1617+
fn test_chunk_by() {
16181618
let slice = &[1, 1, 1, 3, 3, 2, 2, 2, 1, 0];
16191619

1620-
let mut iter = slice.group_by(|a, b| a == b);
1620+
let mut iter = slice.chunk_by(|a, b| a == b);
16211621
assert_eq!(iter.next(), Some(&[1, 1, 1][..]));
16221622
assert_eq!(iter.next(), Some(&[3, 3][..]));
16231623
assert_eq!(iter.next(), Some(&[2, 2, 2][..]));
16241624
assert_eq!(iter.next(), Some(&[1][..]));
16251625
assert_eq!(iter.next(), Some(&[0][..]));
16261626
assert_eq!(iter.next(), None);
16271627

1628-
let mut iter = slice.group_by(|a, b| a == b);
1628+
let mut iter = slice.chunk_by(|a, b| a == b);
16291629
assert_eq!(iter.next_back(), Some(&[0][..]));
16301630
assert_eq!(iter.next_back(), Some(&[1][..]));
16311631
assert_eq!(iter.next_back(), Some(&[2, 2, 2][..]));
16321632
assert_eq!(iter.next_back(), Some(&[3, 3][..]));
16331633
assert_eq!(iter.next_back(), Some(&[1, 1, 1][..]));
16341634
assert_eq!(iter.next_back(), None);
16351635

1636-
let mut iter = slice.group_by(|a, b| a == b);
1636+
let mut iter = slice.chunk_by(|a, b| a == b);
16371637
assert_eq!(iter.next(), Some(&[1, 1, 1][..]));
16381638
assert_eq!(iter.next_back(), Some(&[0][..]));
16391639
assert_eq!(iter.next(), Some(&[3, 3][..]));
@@ -1643,26 +1643,26 @@ fn test_group_by() {
16431643
}
16441644

16451645
#[test]
1646-
fn test_group_by_mut() {
1646+
fn test_chunk_by_mut() {
16471647
let slice = &mut [1, 1, 1, 3, 3, 2, 2, 2, 1, 0];
16481648

1649-
let mut iter = slice.group_by_mut(|a, b| a == b);
1649+
let mut iter = slice.chunk_by_mut(|a, b| a == b);
16501650
assert_eq!(iter.next(), Some(&mut [1, 1, 1][..]));
16511651
assert_eq!(iter.next(), Some(&mut [3, 3][..]));
16521652
assert_eq!(iter.next(), Some(&mut [2, 2, 2][..]));
16531653
assert_eq!(iter.next(), Some(&mut [1][..]));
16541654
assert_eq!(iter.next(), Some(&mut [0][..]));
16551655
assert_eq!(iter.next(), None);
16561656

1657-
let mut iter = slice.group_by_mut(|a, b| a == b);
1657+
let mut iter = slice.chunk_by_mut(|a, b| a == b);
16581658
assert_eq!(iter.next_back(), Some(&mut [0][..]));
16591659
assert_eq!(iter.next_back(), Some(&mut [1][..]));
16601660
assert_eq!(iter.next_back(), Some(&mut [2, 2, 2][..]));
16611661
assert_eq!(iter.next_back(), Some(&mut [3, 3][..]));
16621662
assert_eq!(iter.next_back(), Some(&mut [1, 1, 1][..]));
16631663
assert_eq!(iter.next_back(), None);
16641664

1665-
let mut iter = slice.group_by_mut(|a, b| a == b);
1665+
let mut iter = slice.chunk_by_mut(|a, b| a == b);
16661666
assert_eq!(iter.next(), Some(&mut [1, 1, 1][..]));
16671667
assert_eq!(iter.next_back(), Some(&mut [0][..]));
16681668
assert_eq!(iter.next(), Some(&mut [3, 3][..]));

‎library/core/src/slice/iter.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -3241,26 +3241,26 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for IterMut<'a, T> {
32413241

32423242
/// An iterator over slice in (non-overlapping) chunks separated by a predicate.
32433243
///
3244-
/// This struct is created by the [`group_by`] method on [slices].
3244+
/// This struct is created by the [`chunk_by`] method on [slices].
32453245
///
3246-
/// [`group_by`]: slice::group_by
3246+
/// [`chunk_by`]: slice::chunk_by
32473247
/// [slices]: slice
3248-
#[unstable(feature = "slice_group_by", issue = "80552")]
3248+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
32493249
#[must_use = "iterators are lazy and do nothing unless consumed"]
3250-
pub struct GroupBy<'a, T: 'a, P> {
3250+
pub struct ChunkBy<'a, T: 'a, P> {
32513251
slice: &'a [T],
32523252
predicate: P,
32533253
}
32543254

3255-
#[unstable(feature = "slice_group_by", issue = "80552")]
3256-
impl<'a, T: 'a, P> GroupBy<'a, T, P> {
3255+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3256+
impl<'a, T: 'a, P> ChunkBy<'a, T, P> {
32573257
pub(super) fn new(slice: &'a [T], predicate: P) -> Self {
3258-
GroupBy { slice, predicate }
3258+
ChunkBy { slice, predicate }
32593259
}
32603260
}
32613261

3262-
#[unstable(feature = "slice_group_by", issue = "80552")]
3263-
impl<'a, T: 'a, P> Iterator for GroupBy<'a, T, P>
3262+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3263+
impl<'a, T: 'a, P> Iterator for ChunkBy<'a, T, P>
32643264
where
32653265
P: FnMut(&T, &T) -> bool,
32663266
{
@@ -3293,8 +3293,8 @@ where
32933293
}
32943294
}
32953295

3296-
#[unstable(feature = "slice_group_by", issue = "80552")]
3297-
impl<'a, T: 'a, P> DoubleEndedIterator for GroupBy<'a, T, P>
3296+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3297+
impl<'a, T: 'a, P> DoubleEndedIterator for ChunkBy<'a, T, P>
32983298
where
32993299
P: FnMut(&T, &T) -> bool,
33003300
{
@@ -3315,39 +3315,39 @@ where
33153315
}
33163316
}
33173317

3318-
#[unstable(feature = "slice_group_by", issue = "80552")]
3319-
impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool {}
3318+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3319+
impl<'a, T: 'a, P> FusedIterator for ChunkBy<'a, T, P> where P: FnMut(&T, &T) -> bool {}
33203320

3321-
#[unstable(feature = "slice_group_by", issue = "80552")]
3322-
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
3321+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3322+
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for ChunkBy<'a, T, P> {
33233323
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3324-
f.debug_struct("GroupBy").field("slice", &self.slice).finish()
3324+
f.debug_struct("ChunkBy").field("slice", &self.slice).finish()
33253325
}
33263326
}
33273327

33283328
/// An iterator over slice in (non-overlapping) mutable chunks separated
33293329
/// by a predicate.
33303330
///
3331-
/// This struct is created by the [`group_by_mut`] method on [slices].
3331+
/// This struct is created by the [`chunk_by_mut`] method on [slices].
33323332
///
3333-
/// [`group_by_mut`]: slice::group_by_mut
3333+
/// [`chunk_by_mut`]: slice::chunk_by_mut
33343334
/// [slices]: slice
3335-
#[unstable(feature = "slice_group_by", issue = "80552")]
3335+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
33363336
#[must_use = "iterators are lazy and do nothing unless consumed"]
3337-
pub struct GroupByMut<'a, T: 'a, P> {
3337+
pub struct ChunkByMut<'a, T: 'a, P> {
33383338
slice: &'a mut [T],
33393339
predicate: P,
33403340
}
33413341

3342-
#[unstable(feature = "slice_group_by", issue = "80552")]
3343-
impl<'a, T: 'a, P> GroupByMut<'a, T, P> {
3342+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3343+
impl<'a, T: 'a, P> ChunkByMut<'a, T, P> {
33443344
pub(super) fn new(slice: &'a mut [T], predicate: P) -> Self {
3345-
GroupByMut { slice, predicate }
3345+
ChunkByMut { slice, predicate }
33463346
}
33473347
}
33483348

3349-
#[unstable(feature = "slice_group_by", issue = "80552")]
3350-
impl<'a, T: 'a, P> Iterator for GroupByMut<'a, T, P>
3349+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3350+
impl<'a, T: 'a, P> Iterator for ChunkByMut<'a, T, P>
33513351
where
33523352
P: FnMut(&T, &T) -> bool,
33533353
{
@@ -3381,8 +3381,8 @@ where
33813381
}
33823382
}
33833383

3384-
#[unstable(feature = "slice_group_by", issue = "80552")]
3385-
impl<'a, T: 'a, P> DoubleEndedIterator for GroupByMut<'a, T, P>
3384+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3385+
impl<'a, T: 'a, P> DoubleEndedIterator for ChunkByMut<'a, T, P>
33863386
where
33873387
P: FnMut(&T, &T) -> bool,
33883388
{
@@ -3404,12 +3404,12 @@ where
34043404
}
34053405
}
34063406

3407-
#[unstable(feature = "slice_group_by", issue = "80552")]
3408-
impl<'a, T: 'a, P> FusedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool {}
3407+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3408+
impl<'a, T: 'a, P> FusedIterator for ChunkByMut<'a, T, P> where P: FnMut(&T, &T) -> bool {}
34093409

3410-
#[unstable(feature = "slice_group_by", issue = "80552")]
3411-
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupByMut<'a, T, P> {
3410+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
3411+
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for ChunkByMut<'a, T, P> {
34123412
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3413-
f.debug_struct("GroupByMut").field("slice", &self.slice).finish()
3413+
f.debug_struct("ChunkByMut").field("slice", &self.slice).finish()
34143414
}
34153415
}

‎library/core/src/slice/mod.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub use iter::{ArrayChunks, ArrayChunksMut};
7171
#[unstable(feature = "array_windows", issue = "75027")]
7272
pub use iter::ArrayWindows;
7373

74-
#[unstable(feature = "slice_group_by", issue = "80552")]
75-
pub use iter::{GroupBy, GroupByMut};
74+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
75+
pub use iter::{ChunkBy, ChunkByMut};
7676

7777
#[stable(feature = "split_inclusive", since = "1.51.0")]
7878
pub use iter::{SplitInclusive, SplitInclusiveMut};
@@ -1744,11 +1744,9 @@ impl<T> [T] {
17441744
/// # Examples
17451745
///
17461746
/// ```
1747-
/// #![feature(slice_group_by)]
1748-
///
17491747
/// let slice = &[1, 1, 1, 3, 3, 2, 2, 2];
17501748
///
1751-
/// let mut iter = slice.group_by(|a, b| a == b);
1749+
/// let mut iter = slice.chunk_by(|a, b| a == b);
17521750
///
17531751
/// assert_eq!(iter.next(), Some(&[1, 1, 1][..]));
17541752
/// assert_eq!(iter.next(), Some(&[3, 3][..]));
@@ -1759,24 +1757,22 @@ impl<T> [T] {
17591757
/// This method can be used to extract the sorted subslices:
17601758
///
17611759
/// ```
1762-
/// #![feature(slice_group_by)]
1763-
///
17641760
/// let slice = &[1, 1, 2, 3, 2, 3, 2, 3, 4];
17651761
///
1766-
/// let mut iter = slice.group_by(|a, b| a <= b);
1762+
/// let mut iter = slice.chunk_by(|a, b| a <= b);
17671763
///
17681764
/// assert_eq!(iter.next(), Some(&[1, 1, 2, 3][..]));
17691765
/// assert_eq!(iter.next(), Some(&[2, 3][..]));
17701766
/// assert_eq!(iter.next(), Some(&[2, 3, 4][..]));
17711767
/// assert_eq!(iter.next(), None);
17721768
/// ```
1773-
#[unstable(feature = "slice_group_by", issue = "80552")]
1769+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
17741770
#[inline]
1775-
pub fn group_by<F>(&self, pred: F) -> GroupBy<'_, T, F>
1771+
pub fn chunk_by<F>(&self, pred: F) -> ChunkBy<'_, T, F>
17761772
where
17771773
F: FnMut(&T, &T) -> bool,
17781774
{
1779-
GroupBy::new(self, pred)
1775+
ChunkBy::new(self, pred)
17801776
}
17811777

17821778
/// Returns an iterator over the slice producing non-overlapping mutable
@@ -1789,11 +1785,9 @@ impl<T> [T] {
17891785
/// # Examples
17901786
///
17911787
/// ```
1792-
/// #![feature(slice_group_by)]
1793-
///
17941788
/// let slice = &mut [1, 1, 1, 3, 3, 2, 2, 2];
17951789
///
1796-
/// let mut iter = slice.group_by_mut(|a, b| a == b);
1790+
/// let mut iter = slice.chunk_by_mut(|a, b| a == b);
17971791
///
17981792
/// assert_eq!(iter.next(), Some(&mut [1, 1, 1][..]));
17991793
/// assert_eq!(iter.next(), Some(&mut [3, 3][..]));
@@ -1804,24 +1798,22 @@ impl<T> [T] {
18041798
/// This method can be used to extract the sorted subslices:
18051799
///
18061800
/// ```
1807-
/// #![feature(slice_group_by)]
1808-
///
18091801
/// let slice = &mut [1, 1, 2, 3, 2, 3, 2, 3, 4];
18101802
///
1811-
/// let mut iter = slice.group_by_mut(|a, b| a <= b);
1803+
/// let mut iter = slice.chunk_by_mut(|a, b| a <= b);
18121804
///
18131805
/// assert_eq!(iter.next(), Some(&mut [1, 1, 2, 3][..]));
18141806
/// assert_eq!(iter.next(), Some(&mut [2, 3][..]));
18151807
/// assert_eq!(iter.next(), Some(&mut [2, 3, 4][..]));
18161808
/// assert_eq!(iter.next(), None);
18171809
/// ```
1818-
#[unstable(feature = "slice_group_by", issue = "80552")]
1810+
#[stable(feature = "slice_group_by", since = "CURRENT_RUSTC_VERSION")]
18191811
#[inline]
1820-
pub fn group_by_mut<F>(&mut self, pred: F) -> GroupByMut<'_, T, F>
1812+
pub fn chunk_by_mut<F>(&mut self, pred: F) -> ChunkByMut<'_, T, F>
18211813
where
18221814
F: FnMut(&T, &T) -> bool,
18231815
{
1824-
GroupByMut::new(self, pred)
1816+
ChunkByMut::new(self, pred)
18251817
}
18261818

18271819
/// Divides one slice into two at an index.

‎library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
9898
#![cfg_attr(test, feature(cfg_match))]
9999
#![feature(int_roundings)]
100-
#![feature(slice_group_by)]
101100
#![feature(split_array)]
102101
#![feature(strict_provenance)]
103102
#![feature(strict_provenance_atomic_ptr)]

0 commit comments

Comments
 (0)
Failed to load comments.