Skip to content

Commit

Permalink
Fix new clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 24, 2023
1 parent 3e0382c commit 5c22257
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
15 changes: 12 additions & 3 deletions src/cell/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,19 @@ impl CellBuilder {
) -> Result<(), Error> {
let bits = value.remaining_bits();
if builder.bit_len + bits <= MAX_BIT_LEN {
let mut slice_data = MaybeUninit::<[u8; 128]>::uninit();
let slice_data = unsafe { &mut *(slice_data.as_mut_ptr() as *mut [u8; 128]) };
let slice_data = ok!(value.get_raw(0, slice_data, bits));
// SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid.
let mut slice_data =
unsafe { MaybeUninit::<[MaybeUninit<u8>; 128]>::uninit().assume_init() };

// SAFETY: casting `slice_data` to a `*const [u8]` is safe since `MaybeUninit`
// is guaranteed to have the same layout as `u8`.
// The pointer obtained is valid since it refers to memory owned by `slice_data`
// which is a reference and thus guaranteed to be valid for reads.
let slice_data = unsafe {
&mut *(&mut slice_data as *mut [MaybeUninit<u8>; 128] as *mut [u8; 128])
};

let slice_data = ok!(value.get_raw(0, slice_data, bits));
builder.store_raw(slice_data, bits)
} else {
Err(Error::CellOverflow)
Expand Down
14 changes: 1 addition & 13 deletions src/cell/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,12 @@ impl CellSliceRange {
}

/// A read-only view for a subrange of a cell.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CellSlice<'a> {
cell: &'a DynCell,
range: CellSliceRange,
}

impl<'a> Clone for CellSlice<'a> {
#[inline]
fn clone(&self) -> Self {
Self {
cell: self.cell,
range: self.range,
}
}
}

impl<'a> Copy for CellSlice<'a> {}

impl<'a> AsRef<CellSlice<'a>> for CellSlice<'a> {
#[inline]
fn as_ref(&self) -> &CellSlice<'a> {
Expand Down

0 comments on commit 5c22257

Please sign in to comment.