@@ -503,8 +503,9 @@ impl<T> Vec<T> {
503
503
/// This is highly unsafe, due to the number of invariants that aren't
504
504
/// checked:
505
505
///
506
- /// * `ptr` must have been allocated using the global allocator, such as via
506
+ /// * unless `capacity` is 0 or `T` has size 0, `ptr` must have been allocated using the global allocator, such as via
507
507
/// the [`alloc::alloc`] function.
508
+ /// * `ptr` must not be null.
508
509
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
509
510
/// (`T` having a less strict alignment is not sufficient, the alignment really
510
511
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -514,12 +515,12 @@ impl<T> Vec<T> {
514
515
/// alignment, [`dealloc`] must be called with the same layout `size`.)
515
516
/// * `length` needs to be less than or equal to `capacity`.
516
517
/// * 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 .
518
519
/// * The allocated size in bytes must be no larger than `isize::MAX`.
519
520
/// See the safety documentation of [`pointer::offset`].
520
521
///
521
522
/// 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
523
524
/// upheld.
524
525
///
525
526
/// Violating these may cause problems like corrupting the allocator's
@@ -724,7 +725,7 @@ impl<T, A: Allocator> Vec<T, A> {
724
725
/// This is highly unsafe, due to the number of invariants that aren't
725
726
/// checked:
726
727
///
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`.
728
729
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
729
730
/// (`T` having a less strict alignment is not sufficient, the alignment really
730
731
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -739,7 +740,7 @@ impl<T, A: Allocator> Vec<T, A> {
739
740
/// See the safety documentation of [`pointer::offset`].
740
741
///
741
742
/// 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
743
744
/// upheld.
744
745
///
745
746
/// Violating these may cause problems like corrupting the allocator's
0 commit comments