1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-19 22:19:29 +02:00

Fix example from zerocopy. (#2511)

This was changed incorrectly in #2434.

Fixes #2472.
This commit is contained in:
Andrew Walbran 2024-12-13 09:17:37 +00:00 committed by GitHub
parent 699cceadef
commit fbeef48c50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,8 @@ use std::{mem, slice};
pub unsafe trait IntoBytes {
fn as_bytes(&self) -> &[u8] {
let len = mem::size_of_val(self);
unsafe { slice::from_raw_parts((&raw const self).cast::<u8>(), len) }
let slf: *const Self = self;
unsafe { slice::from_raw_parts(slf.cast::<u8>(), len) }
}
}