Latest Results
pep440/version: fix dead "already trimmed" fast-path in `only_release_trimmed` (#19425)
## Summary
`only_release_trimmed` is intended to short-circuit with a cheap
`.clone()`
when the release segment already has no trailing zeros. The guard
condition was:
```rust
if last_non_zero == self.release().len() {
```
`rposition` returns a zero-based index, so its maximum possible value is
`len - 1`. The value `len` is unreachable, making the "Already trimmed"
branch
permanently dead code. Every call — including the common case of
already-trimmed
versions like `1.2.3` or `3.11` — fell through to the `else` branch and
performed a redundant `Self::new(...)` allocation.
Fix: change the condition to `last_non_zero + 1 ==
self.release().len()`, which
is true exactly when the last non-zero index is the final element of the
slice.
`only_release_trimmed` is called on hot paths in version specifier
simplification, version range normalization, and marker algebra.
## Test Plan
Verified by reading `rposition`'s contract in the standard library docs
—
it returns `Option<usize>` where the index is always in `0..len`. The
corrected
condition can be confirmed by tracing through representative inputs:
- `[1, 2, 3]` → `last_non_zero = 2`, `2 + 1 == 3` ✓ fast-path clone
- `[1, 2, 0]` → `last_non_zero = 1`, `1 + 1 != 3` → trims to `[1, 2]` ✓
- `[0, 0, 0]` → `rposition` returns `None` → `Self::new([0])` ✓
---------
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com> Latest Branches
0%
tk/centralised-environments 0%
+1%
Dev-X25874:fix/pep440-only-release-trimmed-fast-path © 2026 CodSpeed Technology