File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -317,9 +317,14 @@ impl String {
317
317
318
318
/// Creates a new `String` from a length, capacity, and pointer.
319
319
///
320
- /// This is unsafe because:
320
+ /// # Unsafety
321
321
///
322
- /// * We call `Vec::from_raw_parts` to get a `Vec<u8>`;
322
+ /// This is _very_ unsafe because:
323
+ ///
324
+ /// * We call `Vec::from_raw_parts` to get a `Vec<u8>`. Therefore, this
325
+ /// function inherits all of its unsafety, see [its
326
+ /// documentation](../vec/struct.Vec.html#method.from_raw_parts)
327
+ /// for the invariants it expects, they also apply to this function.
323
328
/// * We assume that the `Vec` contains valid UTF-8.
324
329
#[ inline]
325
330
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -227,7 +227,17 @@ impl<T> Vec<T> {
227
227
228
228
/// Creates a `Vec<T>` directly from the raw components of another vector.
229
229
///
230
- /// This is highly unsafe, due to the number of invariants that aren't checked.
230
+ /// # Unsafety
231
+ ///
232
+ /// This is highly unsafe, due to the number of invariants that aren't
233
+ /// checked:
234
+ ///
235
+ /// * `ptr` needs to have been previously allocated via `String`/`Vec<T>`
236
+ /// (at least, it's highly likely to be incorrect if it wasn't).
237
+ /// * `capacity` needs to be the capacity that the pointer was allocated with.
238
+ ///
239
+ /// Violating these may cause problems like corrupting the allocator's
240
+ /// internal datastructures.
231
241
///
232
242
/// # Examples
233
243
///
You can’t perform that action at this time.
0 commit comments