iter repeat: panic on last

This commit is contained in:
Marijn Schouten
2025-10-02 07:12:08 +00:00
parent 42b384ec0d
commit d52744e9fc
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -97,8 +97,9 @@ fn nth(&mut self, n: usize) -> Option<A> {
Some(self.element.clone())
}
#[track_caller]
fn last(self) -> Option<A> {
Some(self.element)
panic!("iterator is infinite");
}
#[track_caller]
+1
View File
@@ -37,6 +37,7 @@ fn test_repeat_count() {
}
#[test]
#[should_panic = "iterator is infinite"]
fn test_repeat_last() {
assert_eq!(repeat(42).last(), Some(42));
}