@@ -483,7 +483,7 @@ impl<T> Vec<T> {
483
483
Self :: with_capacity_in ( capacity, Global )
484
484
}
485
485
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 .
487
487
///
488
488
/// # Safety
489
489
///
@@ -498,12 +498,14 @@ impl<T> Vec<T> {
498
498
/// to be the same size as the pointer was allocated with. (Because similar to
499
499
/// alignment, [`dealloc`] must be called with the same layout `size`.)
500
500
/// * `length` needs to be less than or equal to `capacity`.
501
+ /// * The first `length` values must be properly initialized values of type `T`.
501
502
/// * `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`.
503
504
/// See the safety documentation of [`pointer::offset`].
504
505
///
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.
507
509
///
508
510
/// Violating these may cause problems like corrupting the allocator's
509
511
/// internal data structures. For example it is normally **not** safe
@@ -645,7 +647,8 @@ impl<T, A: Allocator> Vec<T, A> {
645
647
Vec { buf : RawVec :: with_capacity_in ( capacity, alloc) , len : 0 }
646
648
}
647
649
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.
649
652
///
650
653
/// # Safety
651
654
///
@@ -660,12 +663,14 @@ impl<T, A: Allocator> Vec<T, A> {
660
663
/// to be the same size as the pointer was allocated with. (Because similar to
661
664
/// alignment, [`dealloc`] must be called with the same layout `size`.)
662
665
/// * `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`.
665
669
/// See the safety documentation of [`pointer::offset`].
666
670
///
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.
669
674
///
670
675
/// Violating these may cause problems like corrupting the allocator's
671
676
/// internal data structures. For example it is **not** safe
@@ -683,6 +688,7 @@ impl<T, A: Allocator> Vec<T, A> {
683
688
///
684
689
/// [`String`]: crate::string::String
685
690
/// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
691
+ /// [*fit*]: crate::alloc::Allocator#memory-fitting
686
692
///
687
693
/// # Examples
688
694
///
0 commit comments