The “Safety” section of the document of Vec::from_raw_parts says:
length needs to be less than or equal to capacity.
capacity needs to be the capacity that the pointer was allocated with.
I think the first requirement should also add “The first length elements starting from ptr are initialized”. And the second requirement could be relaxed into “capacity needs to be less than or equal to the capacity that the pointer was allocated with”, this is because Allocator::deallocate does not require specifying exact size that the pointer was allocated with.
The “Safety” section of the document of
Vec::from_raw_partssays:I think the first requirement should also add “The first
lengthelements starting fromptrare initialized”. And the second requirement could be relaxed into “capacityneeds to be less than or equal to the capacity that the pointer was allocated with”, this is becauseAllocator::deallocatedoes not require specifying exact size that the pointer was allocated with.