Re: [PATCH 2/2] rust: alloc: add `Vec::dec_len`

Tamir Duberstein
2025-03-17T11:35:37Z

On Mon, Mar 17, 2025 at 7:22 AM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Sun, Mar 16, 2025 at 07:27:22PM -0400, Tamir Duberstein wrote:
> >
> > Does this suit?
>
> I think for dec_ref() it is not the safety requrement that justifies the
> invariant.
>
> I think it should be something along the lines of:
>
> // INVARIANT: We drop ownership for all elements within the range
> // `[self.len - count, self.len]`, hence the updated value of `set.len`
> // represents the exact number of elements stored within `self`.
>
> >
> > > // INVARIANT: By the safety requirements of this method `self.len - count` represents the
> > > // exact number of elements stored within `self`.
>
> Please do not use the email quote mechanism for code snippets, it's confusing
> for readers to figure out by whom it has been written.

Thanks, applied the suggestion.