Rollup merge of #147258 - hkBst:panic-last-repeat, r=scottmcm

iter repeat: panic on last

https://github.com/rust-lang/rust/issues/146660#issuecomment-3356842371
This commit is contained in:
Matthias Krüger
2025-10-18 08:08:36 +02:00
committed by GitHub
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -101,8 +101,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));
}