Skip to content

Commit db74f11

Browse files
authored
Rollup merge of #38874 - derekdreery:patch-1, r=steveklabnik
Update vec.rs Add a warning not to convert char* from c to Vec<u8> (I thought you could until I asked on irc). Reasoning is that it will help people avoid an error that could cause crashes and undefined behaviour. Only drawback is that it could confuse someone not familiar with C, but beginners are unlikely to be using this function anyway.
2 parents 8ccb3ef + 0a85d5f commit db74f11

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libcollections/vec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ impl<T> Vec<T> {
370370
/// * `capacity` needs to be the capacity that the pointer was allocated with.
371371
///
372372
/// Violating these may cause problems like corrupting the allocator's
373-
/// internal datastructures.
373+
/// internal datastructures. For example it is **not** safe
374+
/// to build a `Vec<u8>` from a pointer to a C `char` array and a `size_t`.
374375
///
375376
/// The ownership of `ptr` is effectively transferred to the
376377
/// `Vec<T>` which may then deallocate, reallocate or change the

0 commit comments

Comments
 (0)