diff options
| author | Marijn Schouten <mhkbst@gmail.com> | 2025-09-10 12:40:29 +0000 |
|---|---|---|
| committer | Marijn Schouten <mhkbst@gmail.com> | 2025-09-16 10:09:20 +0000 |
| commit | c89b6a955c9e16c7c96714cea7945945caadcc79 (patch) | |
| tree | 2bc5fa65342887dce60f942f4e84b0db514a31f2 /library/core/src | |
| parent | d1ed52b1f5b78bf66127b670af813b84d57aeedb (diff) | |
| download | rust-c89b6a955c9e16c7c96714cea7945945caadcc79.tar.gz rust-c89b6a955c9e16c7c96714cea7945945caadcc79.zip | |
Iterator repeat: no infinite loop for `last` and `count`
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/iter/sources/repeat.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/core/src/iter/sources/repeat.rs b/library/core/src/iter/sources/repeat.rs index c4f5a483e5c..4bcd5b16aea 100644 --- a/library/core/src/iter/sources/repeat.rs +++ b/library/core/src/iter/sources/repeat.rs @@ -9,7 +9,7 @@ use crate::num::NonZero; /// [`Iterator::take()`], in order to make them finite. /// /// Use [`str::repeat()`] instead of this function if you just want to repeat -/// a char/string `n`th times. +/// a char/string `n` times. /// /// If the element type of the iterator you need does not implement `Clone`, /// or if you do not want to keep the repeated element in memory, you can @@ -98,11 +98,12 @@ impl<A: Clone> Iterator for Repeat<A> { } fn last(self) -> Option<A> { - loop {} + Some(self.element) } + #[track_caller] fn count(self) -> usize { - loop {} + panic!("iterator is infinite"); } } |
