@@ -666,6 +666,10 @@ pub const fn needs_drop<T: ?Sized>() -> bool {
666666/// This means that, for example, the padding byte in `(u8, u16)` is not
667667/// necessarily zeroed.
668668///
669+ /// # Safety
670+ ///
671+ /// The all-zero byte-pattern must represent a valid value of some type `T`.
672+ ///
669673/// There is no guarantee that an all-zero byte-pattern represents a valid value
670674/// of some type `T`. For example, the all-zero byte-pattern is not a valid value
671675/// for reference types (`&T`, `&mut T`) and function pointers. Using `zeroed`
@@ -717,6 +721,10 @@ pub const unsafe fn zeroed<T>() -> T {
717721/// Bypasses Rust's normal memory-initialization checks by pretending to
718722/// produce a value of type `T`, while doing nothing at all.
719723///
724+ /// # Safety
725+ ///
726+ /// Do not use; reserved for legacy code only.
727+ ///
720728/// **This function is deprecated.** Use [`MaybeUninit<T>`] instead.
721729/// It also might be slower than using `MaybeUninit<T>` due to mitigations that were put in place to
722730/// limit the potential harm caused by incorrect use of this function in legacy code.
@@ -1027,6 +1035,14 @@ pub const fn copy<T: Copy>(x: &T) -> T {
10271035/// Interprets `src` as having type `&Dst`, and then reads `src` without moving
10281036/// the contained value.
10291037///
1038+ /// # Safety
1039+ ///
1040+ /// * [`size_of::<Src>`][size_of] must be greater than or equal to [`size_of::<Dst>`][size_of].
1041+ /// * The first [`size_of::<Dst>`][size_of] bytes of memory pointed to by `src` must represent
1042+ /// a valid value of type `Dst`.
1043+ /// * Users must ensure that creating the returned value does not violate Rust's aliasing rules.
1044+ ///
1045+ ///
10301046/// This function will unsafely assume the pointer `src` is valid for [`size_of::<Dst>`][size_of]
10311047/// bytes by transmuting `&Src` to `&Dst` and then reading the `&Dst` (except that this is done
10321048/// in a way that is correct even when `&Dst` has stricter alignment requirements than `&Src`).
0 commit comments