Skip to content

Commit ef21257

Browse files
committed
repeat iter: tests + panic in fold
1 parent 2ebb126 commit ef21257

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

library/core/src/iter/sources/repeat.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ impl<A: Clone> Iterator for Repeat<A> {
102102
}
103103

104104
#[track_caller]
105-
fn count(self) -> usize {
105+
fn fold<B, F>(self, _init: B, _f: F) -> B
106+
where
107+
Self: Sized,
108+
F: FnMut(B, Self::Item) -> B,
109+
{
106110
panic!("iterator is infinite");
107111
}
108112
}

library/coretests/tests/iter/sources.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ fn test_repeat_take_collect() {
3030
assert_eq!(v, vec![42, 42, 42]);
3131
}
3232

33+
#[test]
34+
#[should_panic = "iterator is infinite"]
35+
fn test_repeat_count() {
36+
repeat(42).count();
37+
}
38+
39+
#[test]
40+
fn test_repeat_last() {
41+
assert_eq!(repeat(42).last(), Some(42));
42+
}
43+
3344
#[test]
3445
fn test_repeat_with() {
3546
#[derive(PartialEq, Debug)]

0 commit comments

Comments
 (0)