Skip to content

Commit 6517a0e

Browse files
committed
Auto merge of #25047 - sinkuu:vec_intoiter_override, r=alexcrichton
Override methods `count`, `last`, and `nth` in vec::IntoIter. #24214
2 parents 45b9a34 + 5d8431c commit 6517a0e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/libcollections/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,11 @@ impl<T> Iterator for IntoIter<T> {
17771777
let exact = diff / (if size == 0 {1} else {size});
17781778
(exact, Some(exact))
17791779
}
1780+
1781+
#[inline]
1782+
fn count(self) -> usize {
1783+
self.size_hint().0
1784+
}
17801785
}
17811786

17821787
#[stable(feature = "rust1", since = "1.0.0")]

src/libcollectionstest/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ fn test_split_off() {
542542
assert_eq!(vec2, [5, 6]);
543543
}
544544

545+
#[test]
546+
fn test_into_iter_count() {
547+
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
548+
}
549+
545550
#[bench]
546551
fn bench_new(b: &mut Bencher) {
547552
b.iter(|| {

0 commit comments

Comments
 (0)