Skip to content

Commit 0b9751c

Browse files
committed
Auto merge of rust-lang#99451 - Dylan-DPC:rollup-ceghu18, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#97183 (wf-check generators) - rust-lang#98320 (Mention first and last macro in backtrace) - rust-lang#99335 (Use split_once in FromStr docs) - rust-lang#99347 (Use `LocalDefId` in `OpaqueTypeKey`) - rust-lang#99392 (Fix debuginfo tests.) - rust-lang#99404 (Use span_bug for unexpected field projection type) - rust-lang#99410 (Update invalid atomic ordering lint) - rust-lang#99434 (Fix `Skip::next` for non-fused inner iterators) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8def670 + 32f6ffe commit 0b9751c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

core/src/iter/adapters/skip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
#[inline]
3434
fn next(&mut self) -> Option<I::Item> {
3535
if unlikely(self.n > 0) {
36-
self.iter.nth(crate::mem::take(&mut self.n) - 1);
36+
self.iter.nth(crate::mem::take(&mut self.n) - 1)?;
3737
}
3838
self.iter.next()
3939
}

core/src/str/traits.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,14 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
519519
/// type Err = ParseIntError;
520520
///
521521
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
522-
/// let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' )
523-
/// .split(',')
524-
/// .collect();
525-
///
526-
/// let x_fromstr = coords[0].parse::<i32>()?;
527-
/// let y_fromstr = coords[1].parse::<i32>()?;
522+
/// let (x, y) = s
523+
/// .strip_prefix('(')
524+
/// .and_then(|s| s.strip_suffix(')'))
525+
/// .and_then(|s| s.split_once(','))
526+
/// .unwrap();
527+
///
528+
/// let x_fromstr = x.parse::<i32>()?;
529+
/// let y_fromstr = y.parse::<i32>()?;
528530
///
529531
/// Ok(Point { x: x_fromstr, y: y_fromstr })
530532
/// }

core/tests/iter/adapters/skip.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use core::iter::*;
22

3+
use super::Unfuse;
4+
35
#[test]
46
fn test_iterator_skip() {
57
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
@@ -190,3 +192,12 @@ fn test_skip_nth_back() {
190192
it.by_ref().skip(2).nth_back(10);
191193
assert_eq!(it.next_back(), Some(&1));
192194
}
195+
196+
#[test]
197+
fn test_skip_non_fused() {
198+
let non_fused = Unfuse::new(0..10);
199+
200+
// `Skip` would previously exhaust the iterator in this `next` call and then erroneously try to
201+
// advance it further. `Unfuse` tests that this doesn't happen by panicking in that scenario.
202+
let _ = non_fused.skip(20).next();
203+
}

0 commit comments

Comments
 (0)