From 9b2d03bd60b38c48ddc412963d6c1ea309d196ce Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Wed, 24 Dec 2025 11:37:54 +0000 Subject: [PATCH] =?UTF-8?q?.checked=5Fsub(1).unwrap=5For(0)=20=E2=86=92=20?= =?UTF-8?q?.saturating=5Fsub(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/alloc/src/collections/linked_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index e738c29c237f..c98aeb80628e 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -597,7 +597,7 @@ impl LinkedList { #[must_use] #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn cursor_back(&self) -> Cursor<'_, T, A> { - Cursor { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self } + Cursor { index: self.len.saturating_sub(1), current: self.tail, list: self } } /// Provides a cursor with editing operations at the back element. @@ -607,7 +607,7 @@ impl LinkedList { #[must_use] #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn cursor_back_mut(&mut self) -> CursorMut<'_, T, A> { - CursorMut { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self } + CursorMut { index: self.len.saturating_sub(1), current: self.tail, list: self } } /// Returns `true` if the `LinkedList` is empty. @@ -1432,7 +1432,7 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> { // No current. We're at the start of the list. Yield None and jump to the end. None => { self.current = self.list.tail; - self.index = self.list.len().checked_sub(1).unwrap_or(0); + self.index = self.list.len().saturating_sub(1); } // Have a prev. Yield it and go to the previous element. Some(current) => unsafe { @@ -1559,7 +1559,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> { // No current. We're at the start of the list. Yield None and jump to the end. None => { self.current = self.list.tail; - self.index = self.list.len().checked_sub(1).unwrap_or(0); + self.index = self.list.len().saturating_sub(1); } // Have a prev. Yield it and go to the previous element. Some(current) => unsafe {