@@ -483,7 +483,7 @@ impl<T> Vec<T> {
483483 Self :: with_capacity_in ( capacity, Global )
484484 }
485485
486- /// Creates a `Vec<T>` directly from the raw components of another vector .
486+ /// Creates a `Vec<T>` directly from a pointer, a capacity, and a length .
487487 ///
488488 /// # Safety
489489 ///
@@ -498,12 +498,14 @@ impl<T> Vec<T> {
498498 /// to be the same size as the pointer was allocated with. (Because similar to
499499 /// alignment, [`dealloc`] must be called with the same layout `size`.)
500500 /// * `length` needs to be less than or equal to `capacity`.
501+ /// * The first `length` values must be properly initialized values of type `T`.
501502 /// * `capacity` needs to be the capacity that the pointer was allocated with.
502- /// * The allocated size in bytes must be no larger than `isize::MAX`.
503+ /// * The allocated size in bytes must be no larger than `isize::MAX`.
503504 /// See the safety documentation of [`pointer::offset`].
504505 ///
505- /// To ensure these requirements are easily met, ensure `ptr` has previously
506- /// been allocated via `Vec<T>`.
506+ /// These requirements are always uphead by any `ptr` that has been allocated
507+ /// via `Vec<T>`. Other allocation sources are allowed if the invariants are
508+ /// upheld.
507509 ///
508510 /// Violating these may cause problems like corrupting the allocator's
509511 /// internal data structures. For example it is normally **not** safe
@@ -645,7 +647,8 @@ impl<T, A: Allocator> Vec<T, A> {
645647 Vec { buf : RawVec :: with_capacity_in ( capacity, alloc) , len : 0 }
646648 }
647649
648- /// Creates a `Vec<T, A>` directly from the raw components of another vector.
650+ /// Creates a `Vec<T, A>` directly from a pointer, a capacity, a length,
651+ /// and an allocator.
649652 ///
650653 /// # Safety
651654 ///
@@ -660,12 +663,14 @@ impl<T, A: Allocator> Vec<T, A> {
660663 /// to be the same size as the pointer was allocated with. (Because similar to
661664 /// alignment, [`dealloc`] must be called with the same layout `size`.)
662665 /// * `length` needs to be less than or equal to `capacity`.
663- /// * `capacity` needs to be the capacity that the pointer was allocated with.
664- /// * The allocated size in bytes must be no larger than `isize::MAX`.
666+ /// * The first `length` values must be properly initialized values of type `T`.
667+ /// * `capacity` needs to [fit] the layout size that the pointer was allocated with.
668+ /// * The allocated size in bytes must be no larger than `isize::MAX`.
665669 /// See the safety documentation of [`pointer::offset`].
666670 ///
667- /// To ensure these requirements are easily met, ensure `ptr` has previously
668- /// been allocated via `Vec<T>`.
671+ /// These requirements are always uphead by any `ptr` that has been allocated
672+ /// via `Vec<T>`. Other allocation sources are allowed if the invariants are
673+ /// upheld.
669674 ///
670675 /// Violating these may cause problems like corrupting the allocator's
671676 /// internal data structures. For example it is **not** safe
@@ -683,6 +688,7 @@ impl<T, A: Allocator> Vec<T, A> {
683688 ///
684689 /// [`String`]: crate::string::String
685690 /// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
691+ /// [*fit*]: crate::alloc::Allocator#memory-fitting
686692 ///
687693 /// # Examples
688694 ///
0 commit comments