Skip to content

Commit

Permalink
Stabilize split_inclusive
Browse files Browse the repository at this point in the history
Closes #72360.

Signed-off-by: Ian Jackson <[email protected]>
  • Loading branch information
ijackson committed Jan 4, 2021
1 parent ab5b9ae commit be226e4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
1 change: 0 additions & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#![feature(binary_heap_into_iter_sorted)]
#![feature(binary_heap_drain_sorted)]
#![feature(slice_ptr_get)]
#![feature(split_inclusive)]
#![feature(binary_heap_retain)]
#![feature(inplace_iteration)]
#![feature(iter_map_while)]
Expand Down
26 changes: 11 additions & 15 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,13 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
/// # Example
///
/// ```
/// #![feature(split_inclusive)]
///
/// let slice = [10, 40, 33, 20];
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
/// ```
///
/// [`split_inclusive`]: ../../std/primitive.slice.html#method.split_inclusive
/// [slices]: ../../std/primitive.slice.html
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
pub struct SplitInclusive<'a, T: 'a, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -471,7 +469,7 @@ impl<'a, T: 'a, P: FnMut(&T) -> bool> SplitInclusive<'a, T, P> {
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusive<'_, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -485,7 +483,7 @@ where
}

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<T, P> Clone for SplitInclusive<'_, T, P>
where
P: Clone + FnMut(&T) -> bool,
Expand All @@ -495,7 +493,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<'a, T, P> Iterator for SplitInclusive<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -524,7 +522,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<'a, T, P> DoubleEndedIterator for SplitInclusive<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -549,7 +547,7 @@ where
}
}

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

/// An iterator over the mutable subslices of the vector which are separated
Expand Down Expand Up @@ -689,15 +687,13 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
/// # Example
///
/// ```
/// #![feature(split_inclusive)]
///
/// let mut v = [10, 40, 30, 20, 60, 50];
/// let iter = v.split_inclusive_mut(|num| *num % 3 == 0);
/// ```
///
/// [`split_inclusive_mut`]: ../../std/primitive.slice.html#method.split_inclusive_mut
/// [slices]: ../../std/primitive.slice.html
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
pub struct SplitInclusiveMut<'a, T: 'a, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -714,7 +710,7 @@ impl<'a, T: 'a, P: FnMut(&T) -> bool> SplitInclusiveMut<'a, T, P> {
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusiveMut<'_, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -727,7 +723,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<'a, T, P> Iterator for SplitInclusiveMut<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -767,7 +763,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<'a, T, P> DoubleEndedIterator for SplitInclusiveMut<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -801,7 +797,7 @@ where
}
}

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

/// An iterator over subslices separated by elements that match a predicate
Expand Down
9 changes: 3 additions & 6 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub use iter::ArrayWindows;
#[unstable(feature = "slice_group_by", issue = "80552")]
pub use iter::{GroupBy, GroupByMut};

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
pub use iter::{SplitInclusive, SplitInclusiveMut};

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1549,7 +1549,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(split_inclusive)]
/// let slice = [10, 40, 33, 20];
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
///
Expand All @@ -1563,15 +1562,14 @@ impl<T> [T] {
/// That slice will be the last item returned by the iterator.
///
/// ```
/// #![feature(split_inclusive)]
/// let slice = [3, 10, 40, 33];
/// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
///
/// assert_eq!(iter.next().unwrap(), &[3]);
/// assert_eq!(iter.next().unwrap(), &[10, 40, 33]);
/// assert!(iter.next().is_none());
/// ```
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
#[inline]
pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, T, F>
where
Expand All @@ -1587,7 +1585,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(split_inclusive)]
/// let mut v = [10, 40, 30, 20, 60, 50];
///
/// for group in v.split_inclusive_mut(|num| *num % 3 == 0) {
Expand All @@ -1596,7 +1593,7 @@ impl<T> [T] {
/// }
/// assert_eq!(v, [10, 40, 1, 20, 1, 1]);
/// ```
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
#[inline]
pub fn split_inclusive_mut<F>(&mut self, pred: F) -> SplitInclusiveMut<'_, T, F>
where
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/str/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ pub struct SplitAsciiWhitespace<'a> {
/// See its documentation for more.
///
/// [`split_inclusive`]: str::split_inclusive
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
pub struct SplitInclusive<'a, P: Pattern<'a>>(pub(super) SplitInternal<'a, P>);

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

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

Expand All @@ -1249,22 +1249,22 @@ impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
}
}

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

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

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
for SplitInclusive<'a, P>
{
Expand All @@ -1274,7 +1274,7 @@ impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
}
}

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

impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> {
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub use iter::{EscapeDebug, EscapeDefault, EscapeUnicode};
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
pub use iter::SplitAsciiWhitespace;

#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
use iter::SplitInclusive;

#[unstable(feature = "str_internals", issue = "none")]
Expand Down Expand Up @@ -1227,7 +1227,6 @@ impl str {
/// # Examples
///
/// ```
/// #![feature(split_inclusive)]
/// let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb."
/// .split_inclusive('\n').collect();
/// assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb."]);
Expand All @@ -1238,12 +1237,11 @@ impl str {
/// That substring will be the last item returned by the iterator.
///
/// ```
/// #![feature(split_inclusive)]
/// let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb.\n"
/// .split_inclusive('\n').collect();
/// assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb.\n"]);
/// ```
#[unstable(feature = "split_inclusive", issue = "72360")]
#[stable(feature = "split_inclusive", since = "1.49.0")]
#[inline]
pub fn split_inclusive<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitInclusive<'a, P> {
SplitInclusive(SplitInternal {
Expand Down

1 comment on commit be226e4

@Shadlock0133
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't since version be 1.51?

Please sign in to comment.