From 60838967a4cf8930fcf711ce3286e8e770264955 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Wed, 26 Jun 2024 22:09:06 +0100 Subject: [PATCH] Fix nonsense 'abs' function --- crates/circuit/src/slice.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/circuit/src/slice.rs b/crates/circuit/src/slice.rs index f152b085647b..056adff0a282 100644 --- a/crates/circuit/src/slice.rs +++ b/crates/circuit/src/slice.rs @@ -44,15 +44,6 @@ impl<'py> FromPyObject<'py> for PySequenceIndex<'py> { impl<'py> PySequenceIndex<'py> { /// Specialize this index to a collection of the given `len`, returning a Rust-native type. pub fn with_len(&self, len: usize) -> Result { - let abs = |index: isize| -> Result { - if index >= 0 { - Ok(index as usize) - } else if index == ::std::isize::MIN { - Err(PySequenceIndexError::OutOfRange) - } else { - Ok(-index as usize) - } - }; match self { PySequenceIndex::Int(index) => { let index = if *index >= 0 { @@ -62,7 +53,7 @@ impl<'py> PySequenceIndex<'py> { } index } else { - len.checked_sub(abs(*index)?) + len.checked_sub(index.unsigned_abs()) .ok_or(PySequenceIndexError::OutOfRange)? }; Ok(SequenceIndex::Int(index)) @@ -83,7 +74,7 @@ impl<'py> PySequenceIndex<'py> { start: (indices.start >= 0).then_some(indices.start as usize), // `indices.stop` can be negative if the 0 index should be output. stop: (indices.stop >= 0).then_some(indices.stop as usize), - step: abs(indices.step)?, + step: indices.step.unsigned_abs(), }) } }