From 31a2618647c5b11562c391488ccf2f1690c25277 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 10 Mar 2025 09:16:10 +0000 Subject: [PATCH] docs(allocator): add safety constraint for `String::from_raw_parts_in` (#9640) Add a safety constraint to docs for `String::from_raw_parts_in`. That the `Vec` provided comprises a valid UTF-8 string is a pivotal requirement of this method. I'm not sure how we missed documenting that! Also remove a line of extraneous code from the example. --- crates/oxc_allocator/src/string.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/oxc_allocator/src/string.rs b/crates/oxc_allocator/src/string.rs index 38600b63adf19..025a8e08f7a08 100644 --- a/crates/oxc_allocator/src/string.rs +++ b/crates/oxc_allocator/src/string.rs @@ -196,6 +196,8 @@ impl<'alloc> String<'alloc> { /// * The memory at `ptr` needs to have been previously allocated by the same [`Allocator`]. /// * `length` needs to be less than or equal to `capacity`. /// * `capacity` needs to be the correct value. + /// * The region of memory starting at `ptr` and spanning `length` bytes must contain a valid + /// UTF-8 string. /// /// Violating these may cause problems like corrupting the allocator's internal data structures. /// @@ -205,7 +207,6 @@ impl<'alloc> String<'alloc> { /// /// # Examples /// ``` - /// use std::mem; /// use oxc_allocator::{Allocator, String}; /// /// let allocator = Allocator::default();