Skip to content

Commit c89b6a9

Browse files
committed
Iterator repeat: no infinite loop for last and count
1 parent d1ed52b commit c89b6a9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::num::NonZero;
99
/// [`Iterator::take()`], in order to make them finite.
1010
///
1111
/// Use [`str::repeat()`] instead of this function if you just want to repeat
12-
/// a char/string `n`th times.
12+
/// a char/string `n` times.
1313
///
1414
/// If the element type of the iterator you need does not implement `Clone`,
1515
/// or if you do not want to keep the repeated element in memory, you can
@@ -98,11 +98,12 @@ impl<A: Clone> Iterator for Repeat<A> {
9898
}
9999

100100
fn last(self) -> Option<A> {
101-
loop {}
101+
Some(self.element)
102102
}
103103

104+
#[track_caller]
104105
fn count(self) -> usize {
105-
loop {}
106+
panic!("iterator is infinite");
106107
}
107108
}
108109

0 commit comments

Comments
 (0)