Skip to content

Commit b3a076b

Browse files
committed
docs(allocator): extend doc comments for Vec and RawVec (#12205)
Add `# Errors` and `# Panics` sections to doc comments for `Vec` and `RawVec`.
1 parent 6ff6643 commit b3a076b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

crates/oxc_allocator/src/vec2/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,9 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
905905
/// greater than or equal to `self.len() + additional`. Does nothing if
906906
/// capacity is already sufficient.
907907
///
908-
/// # Panics
908+
/// # Errors
909909
///
910-
/// Panics if the new capacity overflows `u32`.
910+
/// Returns `Err(AllocError)` if unable to reserve requested space in the `Vec`.
911911
///
912912
/// # Examples
913913
///
@@ -932,9 +932,9 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
932932
/// requests. Therefore capacity can not be relied upon to be precisely
933933
/// minimal. Prefer `try_reserve` if future insertions are expected.
934934
///
935-
/// # Panics
935+
/// # Errors
936936
///
937-
/// Panics if the new capacity overflows `u32`.
937+
/// Returns `Err(AllocError)` if unable to reserve requested space in the `Vec`.
938938
///
939939
/// # Examples
940940
///
@@ -1834,6 +1834,7 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
18341834
/// assert_eq!(vec2, [2, 3]);
18351835
/// ```
18361836
#[inline]
1837+
#[must_use]
18371838
pub fn split_off(&mut self, at: usize) -> Self {
18381839
assert!(at <= self.len_usize(), "`at` out of bounds");
18391840

@@ -2035,6 +2036,10 @@ impl<'a, T: 'a + Copy, A: Alloc> Vec<'a, T, A> {
20352036
/// to precompute the total amount of space to reserve in advance. This reduces the potential
20362037
/// maximum number of reallocations needed from one-per-slice to just one.
20372038
///
2039+
/// # Panics
2040+
///
2041+
/// Panics if unable to reserve sufficient capacity in the `Vec` for the slices.
2042+
///
20382043
/// # Examples
20392044
///
20402045
/// ```

crates/oxc_allocator/src/vec2/raw_vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
8585

8686
/// Like `with_capacity` but parameterized over the choice of
8787
/// allocator for the returned RawVec.
88+
///
89+
/// # Panics
90+
///
91+
/// Panics if `cap` is too large.
8892
#[inline]
8993
pub fn with_capacity_in(cap: usize, alloc: &'a A) -> Self {
9094
unsafe {
@@ -358,6 +362,10 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
358362
*/
359363

360364
/// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
365+
///
366+
/// # Errors
367+
///
368+
/// Returns `Err(AllocError)` if unable to reserve requested space in the `RawVec`.
361369
pub fn try_reserve_exact(&mut self, len: u32, additional: usize) -> Result<(), AllocError> {
362370
if self.needs_to_grow(len, additional) {
363371
self.grow_exact(len, additional)?
@@ -394,6 +402,10 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
394402
}
395403

396404
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
405+
///
406+
/// # Errors
407+
///
408+
/// Returns `Err(AllocError)` if unable to reserve requested space in the `RawVec`.
397409
pub fn try_reserve(&mut self, len: u32, additional: usize) -> Result<(), AllocError> {
398410
if self.needs_to_grow(len, additional) {
399411
self.grow_amortized(len, additional)?;
@@ -756,6 +768,10 @@ impl<T, A: Alloc> RawVec<'_, T, A> {
756768

757769
impl<T, A: Alloc> RawVec<'_, T, A> {
758770
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
771+
///
772+
/// # SAFETY
773+
///
774+
/// Not sure what safety invariants of this method are! TODO
759775
pub unsafe fn dealloc_buffer(&mut self) {
760776
let elem_size = mem::size_of::<T>();
761777
if elem_size != 0 {

0 commit comments

Comments
 (0)