Skip to content

Commit 4c246ec

Browse files
committed
Auto merge of #26740 - steveklabnik:gh26737, r=gankro
Fixes #26737.
2 parents 4a21775 + 57eed53 commit 4c246ec

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/libcollections/string.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,14 @@ impl String {
317317

318318
/// Creates a new `String` from a length, capacity, and pointer.
319319
///
320-
/// This is unsafe because:
320+
/// # Unsafety
321321
///
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.
323328
/// * We assume that the `Vec` contains valid UTF-8.
324329
#[inline]
325330
#[stable(feature = "rust1", since = "1.0.0")]

src/libcollections/vec.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,17 @@ impl<T> Vec<T> {
227227

228228
/// Creates a `Vec<T>` directly from the raw components of another vector.
229229
///
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.
231241
///
232242
/// # Examples
233243
///

0 commit comments

Comments
 (0)