public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "David Rheinsberg" <david@readahead.eu>
Cc: rust-for-linux@vger.kernel.org,
	"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust/alloc: add Vec::into_boxed_slice()
Date: Thu, 26 Mar 2026 13:40:01 +0100	[thread overview]
Message-ID: <DHCPYL6AD6DG.35ZOLDNYRWTGV@kernel.org> (raw)
In-Reply-To: <061ea42f-bb21-4dc0-853d-fd2391309d56@app.fastmail.com>

On Thu Mar 26, 2026 at 1:20 PM CET, David Rheinsberg wrote:
> Yes.

So, which one is it?

> Since `slice` is typed, shouldn't this be implied by:
>
>     "`slice` has been allocated with `A`"

Allocator::free() requires

    /// - `layout` must match the `Layout` the allocation has been created with.

I don't see how this is implicitly justified here; the allocation could have
been created with a different layout, i.e. it may be that cap != len.

> There is also no mention of it in `From<Box<[T], A>> for Vec<T, A>`. This
> should have the same requirements, shouldn't it?

This is different, as in this case we can guarantee len == cap.

> I will gladly mention it in v2, though.

We should fix the safety requirement of Box::from_raw().

> Do you want me to add a functionality test, or do you want me to add an
> example for documentation purposes? `doc-test` is a bit ambiguous in that
> regard.

I can be both; examples for edge cases for instance serve both purposes. I.e. it
shouldn't be an excessibe functionality test, but more in general one to three
examples including some edge cases is a good balance. For this one a simple
example should be good enough.

      reply	other threads:[~2026-03-26 12:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26  9:56 [PATCH] rust/alloc: add Vec::into_boxed_slice() David Rheinsberg
2026-03-26 10:33 ` Alice Ryhl
2026-03-26 10:45   ` David Rheinsberg
2026-03-26 10:55     ` Danilo Krummrich
2026-03-26 10:53 ` Danilo Krummrich
2026-03-26 12:20   ` David Rheinsberg
2026-03-26 12:40     ` Danilo Krummrich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DHCPYL6AD6DG.35ZOLDNYRWTGV@kernel.org \
    --to=dakr@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=david@readahead.eu \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=lossin@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox