Skip to content

Rollup of 8 pull requests #83308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
12d6238
Add `as_str` method for split whitespace str iterators
WaffleLapkin Feb 26, 2021
d4fd853
Change formatting of safety comment
WaffleLapkin Feb 26, 2021
c07955c
Fix overflowing length in Vec<ZST> to VecDeque
cuviper Mar 17, 2021
55d9e0f
Include output stream in `panic!()` documentation
jfrimmel Mar 18, 2021
61e5d54
Add more information about panicking
jfrimmel Mar 18, 2021
d5e45b5
Incorporate review feedback #2
jfrimmel Mar 18, 2021
1e322e3
Revert the second deprecation of collections::Bound
bstrie Mar 18, 2021
19bd066
Apply suggestions from code review
jfrimmel Mar 18, 2021
1c8c261
Update LLVM to bring in SIMD updates for WebAssembly
alexcrichton Mar 18, 2021
778e197
Mark early otherwise optimization unsound
spastorino Mar 18, 2021
430c0d1
Do not ICE on ty::Error as an error must already have been reported
oli-obk Mar 19, 2021
9577058
Add a second regression test
oli-obk Mar 19, 2021
1491496
Only build help popup when it's really needed
GuillaumeGomez Dec 12, 2020
e2c70f7
Ignore main.js file length
GuillaumeGomez Mar 19, 2021
ae1a2df
Rollup merge of #79986 - GuillaumeGomez:build-help-when-needed, r=Nem…
Dylan-DPC Mar 19, 2021
f7febc8
Rollup merge of #82570 - WaffleLapkin:split_whitespace_as_str, r=m-ou-se
Dylan-DPC Mar 19, 2021
1a0e32f
Rollup merge of #83244 - cuviper:vec_deque-zst, r=m-ou-se
Dylan-DPC Mar 19, 2021
2cc5d72
Rollup merge of #83254 - jfrimmel:panic_output-stream, r=m-ou-se,josh…
Dylan-DPC Mar 19, 2021
dbf589f
Rollup merge of #83269 - bstrie:revertdep, r=m-ou-se
Dylan-DPC Mar 19, 2021
90e52a1
Rollup merge of #83277 - spastorino:early_otherwise-opt-unsound, r=ol…
Dylan-DPC Mar 19, 2021
767b094
Rollup merge of #83285 - alexcrichton:wasm-simd-update, r=cuviper
Dylan-DPC Mar 19, 2021
51a29cb
Rollup merge of #83297 - oli-obk:why_bug_today_if_you_can_delay_to_to…
Dylan-DPC Mar 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add as_str method for split whitespace str iterators
This commit adds `as_str` methods to `SplitWhitespace` and `SplitAsciiWhitespace`
str iterators. The methods return the remainder, similar to `as_str` methods on
`Chars` and other split iterators.

This commit also makes fields of some iterators `pub(crate)`.
  • Loading branch information
WaffleLapkin committed Feb 26, 2021
commit 12d6238f4d598cfff94ed001b0633ec4490d05dc
3 changes: 2 additions & 1 deletion library/core/src/iter/adapters/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::ops::Try;
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone)]
pub struct Filter<I, P> {
iter: I,
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
pub(crate) iter: I,
predicate: P,
}
impl<I, P> Filter<I, P> {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/iter/adapters/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ use crate::ops::Try;
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone)]
pub struct Map<I, F> {
iter: I,
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
pub(crate) iter: I,
f: F,
}

Expand Down
6 changes: 4 additions & 2 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,11 @@ pub struct Split<'a, T: 'a, P>
where
P: FnMut(&T) -> bool,
{
v: &'a [T],
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
pub(crate) v: &'a [T],
pred: P,
finished: bool,
// Used for `SplitAsciiWhitespace` `as_str` method
pub(crate) finished: bool,
}

impl<'a, T: 'a, P: FnMut(&T) -> bool> Split<'a, T, P> {
Expand Down
55 changes: 55 additions & 0 deletions library/core/src/str/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,30 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> {
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for SplitWhitespace<'_> {}

impl<'a> SplitWhitespace<'a> {
/// Returns remainder of the splitted string
///
/// # Examples
///
/// ```
/// #![feature(str_split_whitespace_as_str)]
///
/// let mut split = "Mary had a little lamb".split_whitespace();
/// assert_eq!(split.as_str(), "Mary had a little lamb");
///
/// split.next();
/// assert_eq!(split.as_str(), "had a little lamb");
///
/// split.by_ref().for_each(drop);
/// assert_eq!(split.as_str(), "");
/// ```
#[inline]
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
pub fn as_str(&self) -> &'a str {
self.inner.iter.as_str()
}
}

#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
impl<'a> Iterator for SplitAsciiWhitespace<'a> {
type Item = &'a str;
Expand Down Expand Up @@ -1234,6 +1258,37 @@ impl<'a> DoubleEndedIterator for SplitAsciiWhitespace<'a> {
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
impl FusedIterator for SplitAsciiWhitespace<'_> {}

impl<'a> SplitAsciiWhitespace<'a> {
/// Returns remainder of the splitted string
///
/// # Examples
///
/// ```
/// #![feature(str_split_whitespace_as_str)]
///
/// let mut split = "Mary had a little lamb".split_ascii_whitespace();
/// assert_eq!(split.as_str(), "Mary had a little lamb");
///
/// split.next();
/// assert_eq!(split.as_str(), "had a little lamb");
///
/// split.by_ref().for_each(drop);
/// assert_eq!(split.as_str(), "");
/// ```
#[inline]
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
pub fn as_str(&self) -> &'a str {
if self.inner.iter.iter.finished {
return "";
}

// Safety:
//
// Slice is created from str.
unsafe { crate::str::from_utf8_unchecked(&self.inner.iter.iter.v) }
}
}

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