Skip to content

Commit 9f3998b

Browse files
committed
Auto merge of rust-lang#77858 - ijackson:split-inclusive, r=KodrAus
Stabilize split_inclusive ### Contents of this MR This stabilises: * `slice::split_inclusive` * `slice::split_inclusive_mut` * `str::split_inclusive` Closes rust-lang#72360. ### A possible concern The proliferation of `split_*` methods is not particularly pretty. The existence of `split_inclusive` seems to invite the addition of `rsplit_inclusive`, `splitn_inclusive`, etc. We could instead have a more general API, along these kinds of lines maybe: ``` pub fn split_generic('a,P,H>(&'a self, pat: P, how: H) -> ... where P: Pattern where H: SplitHow; pub fn split_generic_mut('a,P,H>(&'a mut self, pat: P, how: H) -> ... where P: Pattern where H: SplitHow; trait SplitHow { fn reverse(&self) -> bool; fn inclusive -> bool; fn limit(&self) -> Option<usize>; } pub struct SplitFwd; ... pub struct SplitRevInclN(pub usize); ``` But maybe that is worse. ### Let us defer that? ### This seems like a can of worms. I think we can defer opening it now; if and when we have something more general, these two methods can become convenience aliases. But I thought I would mention it so the lang API team can consider it and have an opinion.
2 parents fc93e47 + 5584224 commit 9f3998b

File tree

6 files changed

+22
-34
lines changed

6 files changed

+22
-34
lines changed

library/alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(binary_heap_into_iter_sorted)]
1515
#![feature(binary_heap_drain_sorted)]
1616
#![feature(slice_ptr_get)]
17-
#![feature(split_inclusive)]
1817
#![feature(binary_heap_retain)]
1918
#![feature(inplace_iteration)]
2019
#![feature(iter_map_while)]

library/core/src/slice/iter.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,13 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
446446
/// # Example
447447
///
448448
/// ```
449-
/// #![feature(split_inclusive)]
450-
///
451449
/// let slice = [10, 40, 33, 20];
452450
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
453451
/// ```
454452
///
455453
/// [`split_inclusive`]: ../../std/primitive.slice.html#method.split_inclusive
456454
/// [slices]: ../../std/primitive.slice.html
457-
#[unstable(feature = "split_inclusive", issue = "72360")]
455+
#[stable(feature = "split_inclusive", since = "1.51.0")]
458456
pub struct SplitInclusive<'a, T: 'a, P>
459457
where
460458
P: FnMut(&T) -> bool,
@@ -471,7 +469,7 @@ impl<'a, T: 'a, P: FnMut(&T) -> bool> SplitInclusive<'a, T, P> {
471469
}
472470
}
473471

474-
#[unstable(feature = "split_inclusive", issue = "72360")]
472+
#[stable(feature = "split_inclusive", since = "1.51.0")]
475473
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusive<'_, T, P>
476474
where
477475
P: FnMut(&T) -> bool,
@@ -485,7 +483,7 @@ where
485483
}
486484

487485
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
488-
#[unstable(feature = "split_inclusive", issue = "72360")]
486+
#[stable(feature = "split_inclusive", since = "1.51.0")]
489487
impl<T, P> Clone for SplitInclusive<'_, T, P>
490488
where
491489
P: Clone + FnMut(&T) -> bool,
@@ -495,7 +493,7 @@ where
495493
}
496494
}
497495

498-
#[unstable(feature = "split_inclusive", issue = "72360")]
496+
#[stable(feature = "split_inclusive", since = "1.51.0")]
499497
impl<'a, T, P> Iterator for SplitInclusive<'a, T, P>
500498
where
501499
P: FnMut(&T) -> bool,
@@ -524,7 +522,7 @@ where
524522
}
525523
}
526524

527-
#[unstable(feature = "split_inclusive", issue = "72360")]
525+
#[stable(feature = "split_inclusive", since = "1.51.0")]
528526
impl<'a, T, P> DoubleEndedIterator for SplitInclusive<'a, T, P>
529527
where
530528
P: FnMut(&T) -> bool,
@@ -549,7 +547,7 @@ where
549547
}
550548
}
551549

552-
#[unstable(feature = "split_inclusive", issue = "72360")]
550+
#[stable(feature = "split_inclusive", since = "1.51.0")]
553551
impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool {}
554552

555553
/// An iterator over the mutable subslices of the vector which are separated
@@ -689,15 +687,13 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
689687
/// # Example
690688
///
691689
/// ```
692-
/// #![feature(split_inclusive)]
693-
///
694690
/// let mut v = [10, 40, 30, 20, 60, 50];
695691
/// let iter = v.split_inclusive_mut(|num| *num % 3 == 0);
696692
/// ```
697693
///
698694
/// [`split_inclusive_mut`]: ../../std/primitive.slice.html#method.split_inclusive_mut
699695
/// [slices]: ../../std/primitive.slice.html
700-
#[unstable(feature = "split_inclusive", issue = "72360")]
696+
#[stable(feature = "split_inclusive", since = "1.51.0")]
701697
pub struct SplitInclusiveMut<'a, T: 'a, P>
702698
where
703699
P: FnMut(&T) -> bool,
@@ -714,7 +710,7 @@ impl<'a, T: 'a, P: FnMut(&T) -> bool> SplitInclusiveMut<'a, T, P> {
714710
}
715711
}
716712

717-
#[unstable(feature = "split_inclusive", issue = "72360")]
713+
#[stable(feature = "split_inclusive", since = "1.51.0")]
718714
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusiveMut<'_, T, P>
719715
where
720716
P: FnMut(&T) -> bool,
@@ -727,7 +723,7 @@ where
727723
}
728724
}
729725

730-
#[unstable(feature = "split_inclusive", issue = "72360")]
726+
#[stable(feature = "split_inclusive", since = "1.51.0")]
731727
impl<'a, T, P> Iterator for SplitInclusiveMut<'a, T, P>
732728
where
733729
P: FnMut(&T) -> bool,
@@ -767,7 +763,7 @@ where
767763
}
768764
}
769765

770-
#[unstable(feature = "split_inclusive", issue = "72360")]
766+
#[stable(feature = "split_inclusive", since = "1.51.0")]
771767
impl<'a, T, P> DoubleEndedIterator for SplitInclusiveMut<'a, T, P>
772768
where
773769
P: FnMut(&T) -> bool,
@@ -801,7 +797,7 @@ where
801797
}
802798
}
803799

804-
#[unstable(feature = "split_inclusive", issue = "72360")]
800+
#[stable(feature = "split_inclusive", since = "1.51.0")]
805801
impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> bool {}
806802

807803
/// An iterator over subslices separated by elements that match a predicate

library/core/src/slice/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub use iter::ArrayWindows;
6060
#[unstable(feature = "slice_group_by", issue = "80552")]
6161
pub use iter::{GroupBy, GroupByMut};
6262

63-
#[unstable(feature = "split_inclusive", issue = "72360")]
63+
#[stable(feature = "split_inclusive", since = "1.51.0")]
6464
pub use iter::{SplitInclusive, SplitInclusiveMut};
6565

6666
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1546,7 +1546,6 @@ impl<T> [T] {
15461546
/// # Examples
15471547
///
15481548
/// ```
1549-
/// #![feature(split_inclusive)]
15501549
/// let slice = [10, 40, 33, 20];
15511550
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
15521551
///
@@ -1560,15 +1559,14 @@ impl<T> [T] {
15601559
/// That slice will be the last item returned by the iterator.
15611560
///
15621561
/// ```
1563-
/// #![feature(split_inclusive)]
15641562
/// let slice = [3, 10, 40, 33];
15651563
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
15661564
///
15671565
/// assert_eq!(iter.next().unwrap(), &[3]);
15681566
/// assert_eq!(iter.next().unwrap(), &[10, 40, 33]);
15691567
/// assert!(iter.next().is_none());
15701568
/// ```
1571-
#[unstable(feature = "split_inclusive", issue = "72360")]
1569+
#[stable(feature = "split_inclusive", since = "1.51.0")]
15721570
#[inline]
15731571
pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, T, F>
15741572
where
@@ -1584,7 +1582,6 @@ impl<T> [T] {
15841582
/// # Examples
15851583
///
15861584
/// ```
1587-
/// #![feature(split_inclusive)]
15881585
/// let mut v = [10, 40, 30, 20, 60, 50];
15891586
///
15901587
/// for group in v.split_inclusive_mut(|num| *num % 3 == 0) {
@@ -1593,7 +1590,7 @@ impl<T> [T] {
15931590
/// }
15941591
/// assert_eq!(v, [10, 40, 1, 20, 1, 1]);
15951592
/// ```
1596-
#[unstable(feature = "split_inclusive", issue = "72360")]
1593+
#[stable(feature = "split_inclusive", since = "1.51.0")]
15971594
#[inline]
15981595
pub fn split_inclusive_mut<F>(&mut self, pred: F) -> SplitInclusiveMut<'_, T, F>
15991596
where

library/core/src/str/iter.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ pub struct SplitAsciiWhitespace<'a> {
11741174
/// See its documentation for more.
11751175
///
11761176
/// [`split_inclusive`]: str::split_inclusive
1177-
#[unstable(feature = "split_inclusive", issue = "72360")]
1177+
#[stable(feature = "split_inclusive", since = "1.51.0")]
11781178
pub struct SplitInclusive<'a, P: Pattern<'a>>(pub(super) SplitInternal<'a, P>);
11791179

11801180
#[stable(feature = "split_whitespace", since = "1.1.0")]
@@ -1239,7 +1239,7 @@ impl<'a> DoubleEndedIterator for SplitAsciiWhitespace<'a> {
12391239
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
12401240
impl FusedIterator for SplitAsciiWhitespace<'_> {}
12411241

1242-
#[unstable(feature = "split_inclusive", issue = "72360")]
1242+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12431243
impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
12441244
type Item = &'a str;
12451245

@@ -1249,22 +1249,22 @@ impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
12491249
}
12501250
}
12511251

1252-
#[unstable(feature = "split_inclusive", issue = "72360")]
1252+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12531253
impl<'a, P: Pattern<'a, Searcher: fmt::Debug>> fmt::Debug for SplitInclusive<'a, P> {
12541254
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12551255
f.debug_struct("SplitInclusive").field("0", &self.0).finish()
12561256
}
12571257
}
12581258

12591259
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
1260-
#[unstable(feature = "split_inclusive", issue = "72360")]
1260+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12611261
impl<'a, P: Pattern<'a, Searcher: Clone>> Clone for SplitInclusive<'a, P> {
12621262
fn clone(&self) -> Self {
12631263
SplitInclusive(self.0.clone())
12641264
}
12651265
}
12661266

1267-
#[unstable(feature = "split_inclusive", issue = "72360")]
1267+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12681268
impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
12691269
for SplitInclusive<'a, P>
12701270
{
@@ -1274,7 +1274,7 @@ impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
12741274
}
12751275
}
12761276

1277-
#[unstable(feature = "split_inclusive", issue = "72360")]
1277+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12781278
impl<'a, P: Pattern<'a>> FusedIterator for SplitInclusive<'a, P> {}
12791279

12801280
impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> {
@@ -1284,7 +1284,6 @@ impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> {
12841284
///
12851285
/// ```
12861286
/// #![feature(str_split_inclusive_as_str)]
1287-
/// #![feature(split_inclusive)]
12881287
/// let mut split = "Mary had a little lamb".split_inclusive(' ');
12891288
/// assert_eq!(split.as_str(), "Mary had a little lamb");
12901289
/// split.next();

library/core/src/str/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub use iter::{EscapeDebug, EscapeDefault, EscapeUnicode};
6565
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
6666
pub use iter::SplitAsciiWhitespace;
6767

68-
#[unstable(feature = "split_inclusive", issue = "72360")]
68+
#[stable(feature = "split_inclusive", since = "1.51.0")]
6969
use iter::SplitInclusive;
7070

7171
#[unstable(feature = "str_internals", issue = "none")]
@@ -1227,7 +1227,6 @@ impl str {
12271227
/// # Examples
12281228
///
12291229
/// ```
1230-
/// #![feature(split_inclusive)]
12311230
/// let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb."
12321231
/// .split_inclusive('\n').collect();
12331232
/// assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb."]);
@@ -1238,12 +1237,11 @@ impl str {
12381237
/// That substring will be the last item returned by the iterator.
12391238
///
12401239
/// ```
1241-
/// #![feature(split_inclusive)]
12421240
/// let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb.\n"
12431241
/// .split_inclusive('\n').collect();
12441242
/// assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb.\n"]);
12451243
/// ```
1246-
#[unstable(feature = "split_inclusive", issue = "72360")]
1244+
#[stable(feature = "split_inclusive", since = "1.51.0")]
12471245
#[inline]
12481246
pub fn split_inclusive<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitInclusive<'a, P> {
12491247
SplitInclusive(SplitInternal {

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(never_type)]
1616
#![feature(once_cell)]
1717
#![feature(type_ascription)]
18-
#![feature(split_inclusive)]
1918
#![feature(str_split_once)]
2019
#![feature(iter_intersperse)]
2120
#![recursion_limit = "256"]

0 commit comments

Comments
 (0)