From 3d53ec256492ca86a02f178e4ee3051e970a53bb Mon Sep 17 00:00:00 2001 From: semihbkgr Date: Mon, 28 Oct 2024 22:56:06 +0300 Subject: [PATCH] use new raw pointer expression --- src/unsafe-rust/unsafe-traits.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/unsafe-rust/unsafe-traits.md b/src/unsafe-rust/unsafe-traits.md index 435a8790d8a..ba279b13428 100644 --- a/src/unsafe-rust/unsafe-traits.md +++ b/src/unsafe-rust/unsafe-traits.md @@ -19,12 +19,11 @@ use std::{mem, slice}; pub unsafe trait IntoBytes { fn as_bytes(&self) -> &[u8] { let len = mem::size_of_val(self); - let slf: *const Self = self; - unsafe { slice::from_raw_parts(slf.cast::(), len) } + unsafe { slice::from_raw_parts((&raw const self).cast::(), len) } } } -/// SAFETY: `u32` has no padding bytes. +// SAFETY: `u32` has a defined representation and no padding. unsafe impl IntoBytes for u32 {} ```