gfx-rs/wgpu · error

split_off() requires a one-sided range

Error message

split_off() requires a one-sided range

What it means

WriteOnly::split_off only supports one-sided (unbounded) ranges — ..end or start.. — and panics for any other range. Passing a bounded range (a..b) or a fully unbounded/full range means there is no single side to split off, so the method rejects it.

Source

Thrown at wgpu-types/src/write_only.rs:577

                        *self = short;
                        None
                    }
                }
            }
            (Bound::Unbounded, Bound::Excluded(&mid)) => {
                match mem::take(self).split_at_checked(mid) {
                    Ok((front, back)) => {
                        *self = back;
                        Some(front)
                    }
                    Err(short) => {
                        *self = short;
                        None
                    }
                }
            }
            _ => {
                panic!("split_off() requires a one-sided range")
            }
        }
    }

    /// Shrinks `self` to no longer refer to its first element, and returns a reference to that
    /// element.
    ///
    /// Returns `None` if `self` is empty.
    #[inline]
    #[must_use]
    pub const fn split_off_first(&mut self) -> Option<WriteOnly<'a, T>> {
        let len = self.len();
        if let Some(new_len) = len.checked_sub(1) {
            let ptr: NonNull<T> = self.as_raw_element_ptr();

            // SAFETY: covers exactly everything but the first element
            *self = unsafe { WriteOnly::new(NonNull::slice_from_raw_parts(ptr.add(1), new_len)) };

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Pass a one-sided range: slice.split_off(i..) to remove the first i elements, or slice.split_off(..i) for the trailing side.
  2. If you need a bounded region, use the slice/get_by_mut APIs that accept a..b ranges instead of split_off.
  3. Construct the range explicitly as (start..) so the compiler picks RangeFrom.

Example fix

// before
let rest = slice.split_off(4..8); // bounded range: panics
// after
let rest = slice.split_off(4..); // one-sided range
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Calling slice.split_off(range) where range is Range { start: a, end: b } (or RangeFull/RangeInclusive) instead of RangeFrom (a..) or RangeTo (..b).

Common situations: Confusing split_off with slice/sub-slicing APIs that accept a..b ranges; reusing a Range a..b captured elsewhere and passing it to split_off.

Related errors


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/a16125d23368dfe3. Report an issue: GitHub.