Skip to content

Commit b4b7558

Browse files
committed
iter repeat: panic on last
1 parent 42b384e commit b4b7558

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<A: Clone> Iterator for Repeat<A> {
9898
}
9999

100100
fn last(self) -> Option<A> {
101-
Some(self.element)
101+
panic!("iterator is infinite");
102102
}
103103

104104
#[track_caller]

library/coretests/tests/iter/sources.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn test_repeat_count() {
3737
}
3838

3939
#[test]
40+
#[should_panic = "iterator is infinite"]
4041
fn test_repeat_last() {
4142
assert_eq!(repeat(42).last(), Some(42));
4243
}

0 commit comments

Comments
 (0)