@@ -490,8 +490,6 @@ impl<T> Vec<T> {
490
490
/// This is highly unsafe, due to the number of invariants that aren't
491
491
/// checked:
492
492
///
493
- /// * `ptr` needs to have been previously allocated via [`String`]/`Vec<T>`
494
- /// (at least, it's highly likely to be incorrect if it wasn't).
495
493
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
496
494
/// (`T` having a less strict alignment is not sufficient, the alignment really
497
495
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -500,6 +498,12 @@ impl<T> Vec<T> {
500
498
/// to be the same size as the pointer was allocated with. (Because similar to
501
499
/// alignment, [`dealloc`] must be called with the same layout `size`.)
502
500
/// * `length` needs to be less than or equal to `capacity`.
501
+ /// * `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
+ /// See the safety documentation of [`pointer::offset`].
504
+ ///
505
+ /// To ensure these requirements are easily met, ensure `ptr` has previously
506
+ /// been allocated via `Vec<T>`.
503
507
///
504
508
/// Violating these may cause problems like corrupting the allocator's
505
509
/// internal data structures. For example it is normally **not** safe
@@ -648,14 +652,20 @@ impl<T, A: Allocator> Vec<T, A> {
648
652
/// This is highly unsafe, due to the number of invariants that aren't
649
653
/// checked:
650
654
///
651
- /// * `ptr` needs to have been previously allocated via [`String`]/`Vec<T>`
652
- /// (at least, it's highly likely to be incorrect if it wasn't).
653
- /// * `T` needs to have the same size and alignment as what `ptr` was allocated with.
655
+ /// * `T` needs to have the same alignment as what `ptr` was allocated with.
654
656
/// (`T` having a less strict alignment is not sufficient, the alignment really
655
657
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
656
658
/// allocated and deallocated with the same layout.)
659
+ /// * The size of `T` times the `capacity` (ie. the allocated size in bytes) needs
660
+ /// to be the same size as the pointer was allocated with. (Because similar to
661
+ /// alignment, [`dealloc`] must be called with the same layout `size`.)
657
662
/// * `length` needs to be less than or equal to `capacity`.
658
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`.
665
+ /// See the safety documentation of [`pointer::offset`].
666
+ ///
667
+ /// To ensure these requirements are easily met, ensure `ptr` has previously
668
+ /// been allocated via `Vec<T>`.
659
669
///
660
670
/// Violating these may cause problems like corrupting the allocator's
661
671
/// internal data structures. For example it is **not** safe
0 commit comments