@@ -503,8 +503,9 @@ impl<T> Vec<T> {
503503 /// This is highly unsafe, due to the number of invariants that aren't
504504 /// checked:
505505 ///
506- /// * `ptr` must have been allocated using the global allocator, such as via
506+ /// * unless `capacity` is 0, `ptr` must have been allocated using the global allocator, such as via
507507 /// the [`alloc::alloc`] function.
508+ /// * `ptr` must not be null.
508509 /// * `T` needs to have the same alignment as what `ptr` was allocated with.
509510 /// (`T` having a less strict alignment is not sufficient, the alignment really
510511 /// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -514,12 +515,12 @@ impl<T> Vec<T> {
514515 /// alignment, [`dealloc`] must be called with the same layout `size`.)
515516 /// * `length` needs to be less than or equal to `capacity`.
516517 /// * The first `length` values must be properly initialized values of type `T`.
517- /// * `capacity` needs to be the capacity that the pointer was allocated with.
518+ /// * `capacity` needs to be the capacity that the pointer was allocated with, or 0 in the case of a dangling pointer .
518519 /// * The allocated size in bytes must be no larger than `isize::MAX`.
519520 /// See the safety documentation of [`pointer::offset`].
520521 ///
521522 /// These requirements are always upheld by any `ptr` that has been allocated
522- /// via `Vec<T>`. Other allocation sources are allowed if the invariants are
523+ /// via `Vec<T>`. Note that a `Vec` of capacity 0 does not allocate. Other allocation sources are allowed if the invariants are
523524 /// upheld.
524525 ///
525526 /// Violating these may cause problems like corrupting the allocator's
@@ -724,7 +725,7 @@ impl<T, A: Allocator> Vec<T, A> {
724725 /// This is highly unsafe, due to the number of invariants that aren't
725726 /// checked:
726727 ///
727- /// * `ptr` must be [*currently allocated*] via the given allocator `alloc`.
728+ /// * unless `capacity` is 0, `ptr` must be [*currently allocated*] via the given allocator `alloc`.
728729 /// * `T` needs to have the same alignment as what `ptr` was allocated with.
729730 /// (`T` having a less strict alignment is not sufficient, the alignment really
730731 /// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -739,7 +740,7 @@ impl<T, A: Allocator> Vec<T, A> {
739740 /// See the safety documentation of [`pointer::offset`].
740741 ///
741742 /// These requirements are always upheld by any `ptr` that has been allocated
742- /// via `Vec<T, A>`. Other allocation sources are allowed if the invariants are
743+ /// via `Vec<T, A>`. Note that a `Vec` of capacity 0 does not allocate. Other allocation sources are allowed if the invariants are
743744 /// upheld.
744745 ///
745746 /// Violating these may cause problems like corrupting the allocator's
0 commit comments