Re: [PATCH] rust/alloc: add Vec::into_boxed_slice()
From: Danilo Krummrich
Date: Thu Mar 26 2026 - 08:47:51 EST
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.