From 4dda047de346ae68fa760548f7ae63e3ae736146 Mon Sep 17 00:00:00 2001 From: jmaargh Date: Tue, 19 Apr 2022 21:12:55 +0100 Subject: Clarify docs for from_raw_parts Original safety explanation for from_raw_parts was unclear on safety for consuming a C string. This clarifies when doing so is safe. --- library/alloc/src/vec/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'library/alloc/src/vec') diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8c2f52172ee..9bf42e779c9 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -489,8 +489,10 @@ impl Vec { /// * `length` needs to be less than or equal to `capacity`. /// /// Violating these may cause problems like corrupting the allocator's - /// internal data structures. For example it is **not** safe - /// to build a `Vec` from a pointer to a C `char` array with length `size_t`. + /// internal data structures. For example it is normally **not** safe + /// to build a `Vec` from a pointer to a C `char` array with length + /// `size_t`, doing so is only safe if the array was initially allocated by + /// a `Vec` or `String`. /// It's also not safe to build one from a `Vec` and its length, because /// the allocator cares about the alignment, and these two types have different /// alignments. The buffer was allocated with alignment 2 (for `u16`), but after -- cgit 1.4.1-3-g733a5