diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 920e559cc4aa3..f1ca66f87a5a3 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -171,7 +171,9 @@ impl Layout { /// /// # Safety /// - /// This function is only safe to call if the following conditions hold: + /// This function is safe to call if the pointer is safe to reborrow as `&T` + /// (in which case you could also call [`Layout::for_value`]). Otherwise, + /// the following conditions must hold: /// /// - If `T` is `Sized`, this function is always safe to call. /// - If the unsized tail of `T` is: @@ -186,7 +188,8 @@ impl Layout { /// call, but may panic or otherwise return the wrong value, as the /// extern type's layout is not known. This is the same behavior as /// [`Layout::for_value`] on a reference to an extern type tail. - /// - otherwise, it is conservatively not allowed to call this function. + /// - otherwise, it is conservatively allowed to call this function + /// only when it would be safe to reborrow `t` as a shared reference. /// /// [trait object]: ../../book/ch17-02-trait-objects.html /// [extern type]: ../../unstable-book/language-features/extern-types.html diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 9195da5a44f42..473b578fcc839 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -351,7 +351,9 @@ pub const fn size_of_val(val: &T) -> usize { /// /// # Safety /// -/// This function is only safe to call if the following conditions hold: +/// This function is safe to call if the pointer is safe to reborrow as `&T` +/// (in which case you could also call [`size_of_val`]). Otherwise, the +/// following conditions must hold: /// /// - If `T` is `Sized`, this function is always safe to call. /// - If the unsized tail of `T` is: @@ -366,7 +368,8 @@ pub const fn size_of_val(val: &T) -> usize { /// call, but may panic or otherwise return the wrong value, as the /// extern type's layout is not known. This is the same behavior as /// [`size_of_val`] on a reference to a type with an extern type tail. -/// - otherwise, it is conservatively not allowed to call this function. +/// - otherwise, it is conservatively allowed to call this function +/// only when it would be safe to reborrow `val` as a shared reference. /// /// [trait object]: ../../book/ch17-02-trait-objects.html /// [extern type]: ../../unstable-book/language-features/extern-types.html @@ -497,7 +500,9 @@ pub const fn align_of_val(val: &T) -> usize { /// /// # Safety /// -/// This function is only safe to call if the following conditions hold: +/// This function is safe to call if the pointer is safe to reborrow as `&T` +/// (in which case you could also call [`align_of_val`]). Otherwise, the +/// following conditions must hold: /// /// - If `T` is `Sized`, this function is always safe to call. /// - If the unsized tail of `T` is: @@ -512,7 +517,8 @@ pub const fn align_of_val(val: &T) -> usize { /// call, but may panic or otherwise return the wrong value, as the /// extern type's layout is not known. This is the same behavior as /// [`align_of_val`] on a reference to a type with an extern type tail. -/// - otherwise, it is conservatively not allowed to call this function. +/// - otherwise, it is conservatively allowed to call this function +/// only when it would be safe to reborrow `val` as a shared reference. /// /// [trait object]: ../../book/ch17-02-trait-objects.html /// [extern type]: ../../unstable-book/language-features/extern-types.html