mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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:
@@ -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]
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user