Skip to content

Commit

Permalink
Fix unused_qualifications lints with 1.80 (#81)
Browse files Browse the repository at this point in the history
In Rust 1.80, `core::mem::size_of` is now part of the standard
prelude, so `unused_qualifications` will warn when it is qualified.

Also did the same for `MaybeUnit` since it was in the same
module.
  • Loading branch information
waywardmonkeys authored Sep 13, 2024
1 parent b5737d2 commit 0781b3b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::core::{
SizeValue, WriteInto, Writer,
};

use core::mem::{size_of, MaybeUninit};

pub struct ArrayMetadata {
pub stride: SizeValue,
pub el_padding: u64,
Expand Down Expand Up @@ -68,8 +70,7 @@ where
fn write_into<B: BufferMut>(&self, writer: &mut Writer<B>) {
if_pod_and_little_endian!(if pod_and_little_endian {
let ptr = self.as_ptr() as *const u8;
let byte_slice: &[u8] =
unsafe { core::slice::from_raw_parts(ptr, core::mem::size_of::<Self>()) };
let byte_slice: &[u8] = unsafe { core::slice::from_raw_parts(ptr, size_of::<Self>()) };
writer.write_slice(byte_slice);
} else {
for elem in self {
Expand All @@ -89,7 +90,7 @@ where
if_pod_and_little_endian!(if pod_and_little_endian {
let ptr = self.as_mut_ptr() as *mut u8;
let byte_slice: &mut [u8] =
unsafe { core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<Self>()) };
unsafe { core::slice::from_raw_parts_mut(ptr, size_of::<Self>()) };
reader.read_slice(byte_slice);
} else {
for elem in self {
Expand All @@ -107,11 +108,11 @@ where
#[inline]
fn create_from<B: BufferRef>(reader: &mut Reader<B>) -> Self {
if_pod_and_little_endian!(if pod_and_little_endian {
let mut me = core::mem::MaybeUninit::zeroed();
let ptr: *mut core::mem::MaybeUninit<Self> = &mut me;
let mut me = MaybeUninit::zeroed();
let ptr: *mut MaybeUninit<Self> = &mut me;
let ptr = ptr.cast::<u8>();
let byte_slice: &mut [u8] =
unsafe { core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<Self>()) };
unsafe { core::slice::from_raw_parts_mut(ptr, size_of::<Self>()) };
reader.read_slice(byte_slice);
// SAFETY: All values were properly initialized by reading the bytes.
unsafe { me.assume_init() }
Expand Down

0 comments on commit 0781b3b

Please # to comment.