Skip to content

Commit d52744e

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

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ impl<A: Clone> Iterator for Repeat<A> {
9797
Some(self.element.clone())
9898
}
9999

100+
#[track_caller]
100101
fn last(self) -> Option<A> {
101-
Some(self.element)
102+
panic!("iterator is infinite");
102103
}
103104

104105
#[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)