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 a7ca443
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 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
14 changes: 7 additions & 7 deletions src/dict/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl<'a> RawIter<'a> {
builder: Box::default(),
reversed,
signed,
}
};
};

segments.push(IterSegment {
Expand Down Expand Up @@ -957,13 +957,13 @@ impl<'a> RawValues<'a> {
let mut segments = Vec::new();
if let Some(root) = root {
let Ok(data) = root.as_slice() else {
return Self {
segments: Vec::new(),
status: IterStatus::Pruned,
reversed,
signed,
};
return Self {
segments: Vec::new(),
status: IterStatus::Pruned,
reversed,
signed,
};
};

segments.push(ValuesSegment {
data,
Expand Down
3 changes: 2 additions & 1 deletion src/dict/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ where
bound: DictBound,
signed: bool,
) -> Result<Option<(K, CellSlice<'_>)>, Error> {
let Some((key, value)) = ok!(dict_find_bound(self.root.as_ref(), K::BITS, bound, signed)) else {
let Some((key, value)) = ok!(dict_find_bound(self.root.as_ref(), K::BITS, bound, signed))
else {
return Ok(None);
};
match K::from_raw_data(key.raw_data()) {
Expand Down
4 changes: 3 additions & 1 deletion src/models/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ impl BlockchainConfig {

/// Tries to get a parameter from the blockchain config.
pub fn get<'a, T: KnownConfigParam<'a>>(&'a self) -> Result<Option<T::Value>, Error> {
let Some(mut slice) = ok!(self.get_raw(T::ID)) else { return Ok(None); };
let Some(mut slice) = ok!(self.get_raw(T::ID)) else {
return Ok(None);
};
match <T::Wrapper as Load<'a>>::load_from(&mut slice) {
Ok(wrapped) => Ok(Some(wrapped.into_inner())),
Err(e) => Err(e),
Expand Down
2 changes: 1 addition & 1 deletion src/models/config/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ impl Store for ValidatorSet {
finalizer: &mut dyn Finalizer,
) -> Result<(), Error> {
let Ok(total) = u16::try_from(self.list.len()) else {
return Err(Error::InvalidData)
return Err(Error::InvalidData);
};

// TODO: optimize
Expand Down

0 comments on commit a7ca443

Please sign in to comment.