File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff 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" ) ]
Original file line number Diff line number Diff 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 ///
You can’t perform that action at this time.
0 commit comments