Re: [PATCH v3 1/4] rust: alloc: add Vec::len() <= Vec::capacity invariant
From: Tamir Duberstein
Date: Wed Apr 16 2025 - 13:17:43 EST
On Wed, Apr 16, 2025 at 10:41 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> On Mon, Apr 7, 2025 at 4:52 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> >
> > Document the invariant that the vector's length is always less than or
> > equal to its capacity. This is already implied by these other
> > invariants:
> >
> > - `self.len` always represents the exact number of elements stored in
> > the vector.
> > - `self.layout` represents the absolute number of elements that can be
> > stored within the vector without re-allocation.
> >
> > but it doesn't hurt to spell it out. Note that the language references
> > `self.capacity` rather than `self.layout.len` as the latter is zero for
> > a vector of ZSTs.
> >
> > Update a safety comment touched by this patch to correctly reference
> > `realloc` rather than `alloc` and replace "leaves" with "leave" to
> > improve grammar.
> >
> > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
>
> This change has a conflict with the spare_capacity_mut patch in alloc-next.
Indeed. I have resolved it locally but was holding off until some
reviews arrived. I guess I'll respin now.