Skip to content

Commit

Permalink
Rollup merge of rust-lang#63549 - sfanxiang:rev-rposition, r=scottmcm
Browse files Browse the repository at this point in the history
Rev::rposition counts from the wrong end

Introduced in rust-lang#43074.

cc @SimonSapin
  • Loading branch information
Centril authored Sep 5, 2019
2 parents f062076 + 0e597d4 commit 9ac90fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator {
{
self.iter.rfind(predicate)
}

#[inline]
fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool
{
self.iter.position(predicate)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,12 @@ fn test_rposition() {
assert!(v.iter().rposition(g).is_none());
}

#[test]
fn test_rev_rposition() {
let v = [0, 0, 1, 1];
assert_eq!(v.iter().rev().rposition(|&x| x == 1), Some(1));
}

#[test]
#[should_panic]
fn test_rposition_panic() {
Expand Down

0 comments on commit 9ac90fa

Please sign in to comment.