Skip to content

Commit

Permalink
Auto merge of #99451 - Dylan-DPC:rollup-ceghu18, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #97183 (wf-check generators)
 - #98320 (Mention first and last macro in backtrace)
 - #99335 (Use split_once in FromStr docs)
 - #99347 (Use `LocalDefId` in `OpaqueTypeKey`)
 - #99392 (Fix debuginfo tests.)
 - #99404 (Use span_bug for unexpected field projection type)
 - #99410 (Update invalid atomic ordering lint)
 - #99434 (Fix `Skip::next` for non-fused inner iterators)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 19, 2022
2 parents e27d77c + 8157c24 commit 73aff41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/iter/adapters/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
#[inline]
fn next(&mut self) -> Option<I::Item> {
if unlikely(self.n > 0) {
self.iter.nth(crate::mem::take(&mut self.n) - 1);
self.iter.nth(crate::mem::take(&mut self.n) - 1)?;
}
self.iter.next()
}
Expand Down
14 changes: 8 additions & 6 deletions core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,14 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
/// type Err = ParseIntError;
///
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
/// let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' )
/// .split(',')
/// .collect();
///
/// let x_fromstr = coords[0].parse::<i32>()?;
/// let y_fromstr = coords[1].parse::<i32>()?;
/// let (x, y) = s
/// .strip_prefix('(')
/// .and_then(|s| s.strip_suffix(')'))
/// .and_then(|s| s.split_once(','))
/// .unwrap();
///
/// let x_fromstr = x.parse::<i32>()?;
/// let y_fromstr = y.parse::<i32>()?;
///
/// Ok(Point { x: x_fromstr, y: y_fromstr })
/// }
Expand Down
11 changes: 11 additions & 0 deletions core/tests/iter/adapters/skip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::iter::*;

use super::Unfuse;

#[test]
fn test_iterator_skip() {
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
Expand Down Expand Up @@ -190,3 +192,12 @@ fn test_skip_nth_back() {
it.by_ref().skip(2).nth_back(10);
assert_eq!(it.next_back(), Some(&1));
}

#[test]
fn test_skip_non_fused() {
let non_fused = Unfuse::new(0..10);

// `Skip` would previously exhaust the iterator in this `next` call and then erroneously try to
// advance it further. `Unfuse` tests that this doesn't happen by panicking in that scenario.
let _ = non_fused.skip(20).next();
}

0 comments on commit 73aff41

Please sign in to comment.