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(), }) } }