From d68c980c22d95c95ce97b82d03cfd9d48badce30 Mon Sep 17 00:00:00 2001 From: Alessio Date: Fri, 2 Jan 2026 03:53:02 +0100 Subject: [PATCH] library: Document panic condition for `Iterator::last` Added a `# Panics` section to `Iterator::last` to match `Iterator::count`, after the change made in Rust 1.92.0 where now `std::iter::Repeat` panics in these methods instead of doing an infinite `loop`. Cites https://github.com/rust-lang/rust/issues/149707 --- library/core/src/iter/traits/iterator.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 29230b1665380..84da778c3b91c 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -236,6 +236,11 @@ pub trait Iterator { /// doing so, it keeps track of the current element. After [`None`] is /// returned, `last()` will then return the last element it saw. /// + /// # Panics + /// + /// This function might panic if the iterator has more than [`usize::MAX`] + /// elements. + /// /// # Examples /// /// ```