{"record":{"id":"be26997852c6ddb7","repo":"oxc-project/oxc","slug":"iterator-supplied-too-few-elements","errorCode":null,"errorMessage":"Iterator supplied too few elements","messagePattern":"Iterator supplied too few elements","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_allocator/src/arena/alloc.rs","lineNumber":379,"sourceCode":"    ///\n    /// # Example\n    ///\n    /// ```\n    /// # use oxc_allocator::arena::Arena;\n    ///\n    /// let arena = Arena::new();\n    /// let x: &[i32] = arena.alloc_slice_fill_iter([2, 3, 5].iter().cloned().map(|i| i * i));\n    /// assert_eq!(x, [4, 9, 25]);\n    /// ```\n    #[inline(always)]\n    pub fn alloc_slice_fill_iter<T, I>(&self, iter: I) -> &mut [T]\n    where\n        I: IntoIterator<Item = T>,\n        I::IntoIter: ExactSizeIterator,\n    {\n        let mut iter = iter.into_iter();\n        self.alloc_slice_fill_with(iter.len(), |_| {\n            iter.next().expect(\"Iterator supplied too few elements\")\n        })\n    }\n\n    /// Allocate a new slice of size `len` into this `Arena`. Returns an exclusive reference to the slice.\n    ///\n    /// All elements of the slice are initialized to [`T::default()`].\n    ///\n    /// [`T::default()`]: https://doc.rust-lang.org/std/default/trait.Default.html#tymethod.default\n    ///\n    /// # Panics\n    ///\n    /// Panics if reserving space for the slice fails.\n    ///\n    /// # Example\n    ///\n    /// ```\n    /// # use oxc_allocator::arena::Arena;\n    ///","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_allocator/src/arena/alloc.rs#L361-L397","documentation":"Panic inside alloc_slice_fill_iter: the arena allocates a slice sized by the iterator's ExactSizeIterator::len(), then the fill closure calls iter.next().expect(...). If the iterator reports a larger len() than the number of items it actually yields, next() returns None and this contract assertion fires. The fault is a misimplemented ExactSizeIterator, not oxc code.","triggerScenarios":"Thrown at crates/oxc_allocator/src/arena/alloc.rs:379 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the iterator so len() exactly matches the number of remaining items","Collect into a Vec/VecFromIter first and allocate from the collection when the iterator is not trusted","Use alloc_slice_fill_with with an explicit count instead"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}