The docs for Layout::from_size_align_unchecked state that:
size, when rounded up to the nearest multiple of align, must not overflow isize (i.e., the rounded value must be less than or equal to isize::MAX)
alloc::realloc's docs state a different constraint:
new_size, when rounded up to the nearest multiple of layout.align(), must not overflow (i.e., the rounded value must be less than usize::MAX).
So this would be legal according to alloc::realloc's docs:
let layout = alloc::Layout::from_size_align(1, 1);
let ptr1 = alloc::alloc(layout);
let ptr2 = alloc::realloc(ptr1, layout, usize::MAX);
But this results in a call internally:
Layout::from_size_align_unchecked(usize::MAX, 1)
...which is meant to be UB.
I assume this is just that the docs are out of date after #95295.
The docs for
Layout::from_size_align_uncheckedstate that:alloc::realloc's docs state a different constraint:So this would be legal according to
alloc::realloc's docs:But this results in a call internally:
...which is meant to be UB.
I assume this is just that the docs are out of date after #95295.