Add more description for from_raw_parts's unsafety

Fixes #26737.
This commit is contained in:
Steve Klabnik 2015-07-02 13:00:58 -04:00
parent 50cb22f8e0
commit 57eed53041
2 changed files with 18 additions and 3 deletions

View File

@ -317,9 +317,14 @@ impl String {
/// Creates a new `String` from a length, capacity, and pointer. /// Creates a new `String` from a length, capacity, and pointer.
/// ///
/// This is unsafe because: /// # Unsafety
/// ///
/// * We call `Vec::from_raw_parts` to get a `Vec<u8>`; /// This is _very_ unsafe because:
///
/// * We call `Vec::from_raw_parts` to get a `Vec<u8>`. Therefore, this
/// function inherits all of its unsafety, see [its
/// documentation](../vec/struct.Vec.html#method.from_raw_parts)
/// for the invariants it expects, they also apply to this function.
/// * We assume that the `Vec` contains valid UTF-8. /// * We assume that the `Vec` contains valid UTF-8.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View File

@ -227,7 +227,17 @@ impl<T> Vec<T> {
/// Creates a `Vec<T>` directly from the raw components of another vector. /// Creates a `Vec<T>` directly from the raw components of another vector.
/// ///
/// This is highly unsafe, due to the number of invariants that aren't checked. /// # Unsafety
///
/// This is highly unsafe, due to the number of invariants that aren't
/// checked:
///
/// * `ptr` needs to have been previously allocated via `String`/`Vec<T>`
/// (at least, it's highly likely to be incorrect if it wasn't).
/// * `capacity` needs to be the capacity that the pointer was allocated with.
///
/// Violating these may cause problems like corrupting the allocator's
/// internal datastructures.
/// ///
/// # Examples /// # Examples
/// ///