@@ -359,6 +359,12 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
359359/// - a [slice], then the length of the slice tail must be an initialized
360360/// integer, and the size of the *entire value*
361361/// (dynamic tail length + statically sized prefix) must fit in `isize`.
362+ /// For the special case where the dynamic tail length is 0, this function
363+ /// is safe to call.
364+ // NOTE: the reason this is safe is that if an overflow were to occur already with size 0,
365+ // then we would stop compilation as even the "statically known" part of the type would
366+ // already be too big (or the call may be in dead code and optimized away, but then it
367+ // doesn't matter).
362368/// - a [trait object], then the vtable part of the pointer must point
363369/// to a valid vtable acquired by an unsizing coercion, and the size
364370/// of the *entire value* (dynamic tail length + statically sized prefix)
@@ -506,6 +512,8 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
506512/// - a [slice], then the length of the slice tail must be an initialized
507513/// integer, and the size of the *entire value*
508514/// (dynamic tail length + statically sized prefix) must fit in `isize`.
515+ /// For the special case where the dynamic tail length is 0, this function
516+ /// is safe to call.
509517/// - a [trait object], then the vtable part of the pointer must point
510518/// to a valid vtable acquired by an unsizing coercion, and the size
511519/// of the *entire value* (dynamic tail length + statically sized prefix)
0 commit comments