{"record":{"id":"a16125d23368dfe3","repo":"gfx-rs/wgpu","slug":"split-off-requires-a-one-sided-range","errorCode":null,"errorMessage":"split_off() requires a one-sided range","messagePattern":"split_off\\(\\) requires a one-sided range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-types/src/write_only.rs","lineNumber":577,"sourceCode":"                        *self = short;\n                        None\n                    }\n                }\n            }\n            (Bound::Unbounded, Bound::Excluded(&mid)) => {\n                match mem::take(self).split_at_checked(mid) {\n                    Ok((front, back)) => {\n                        *self = back;\n                        Some(front)\n                    }\n                    Err(short) => {\n                        *self = short;\n                        None\n                    }\n                }\n            }\n            _ => {\n                panic!(\"split_off() requires a one-sided range\")\n            }\n        }\n    }\n\n    /// Shrinks `self` to no longer refer to its first element, and returns a reference to that\n    /// element.\n    ///\n    /// Returns `None` if `self` is empty.\n    #[inline]\n    #[must_use]\n    pub const fn split_off_first(&mut self) -> Option<WriteOnly<'a, T>> {\n        let len = self.len();\n        if let Some(new_len) = len.checked_sub(1) {\n            let ptr: NonNull<T> = self.as_raw_element_ptr();\n\n            // SAFETY: covers exactly everything but the first element\n            *self = unsafe { WriteOnly::new(NonNull::slice_from_raw_parts(ptr.add(1), new_len)) };\n","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-types/src/write_only.rs#L559-L595","documentation":"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.","triggerScenarios":"Calling slice.split_off(range) where range is Range { start: a, end: b } (or RangeFull/RangeInclusive) instead of RangeFrom (a..) or RangeTo (..b).","commonSituations":"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.","solutions":["Pass a one-sided range: slice.split_off(i..) to remove the first i elements, or slice.split_off(..i) for the trailing side.","If you need a bounded region, use the slice/get_by_mut APIs that accept a..b ranges instead of split_off.","Construct the range explicitly as (start..) so the compiler picks RangeFrom."],"exampleFix":"// before\nlet rest = slice.split_off(4..8); // bounded range: panics\n// after\nlet rest = slice.split_off(4..); // one-sided range","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call split_off with `i..` or `..i` ranges.","Use slice()/get_by_mut for bounded a..b regions instead of split_off.","Type range variables as RangeFrom/RangeTo so wrong-shaped ranges fail at compile time."],"tags":["panic","rust","buffer-mapping","bad-argument"],"backgroundTag":"unsupported-range-argument","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}