Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed May 31, 2024
1 parent a0bf924 commit 46ea860
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
34 changes: 24 additions & 10 deletions bolos-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@ pub trait SynIteratorExtend: Iterator {
})
}

fn syn_try_fold<C, T>(self) -> Result<C, Error>
fn syn_try_fold<C, T>(mut self) -> Result<C, Error>
where
Self: Sized,
Self: Iterator<Item = Result<T, Error>>,
C: Extend<T> + Default,
{
self.fold(Ok(Default::default()), |acc, x| match (acc, x) {
(Err(e), Ok(_)) | (Ok(_), Err(e)) => Err(e),
(Err(mut e), Err(e2)) => {
e.combine(e2);
Err(e)
}
(Ok(mut v), Ok(x)) => {
v.extend(std::iter::once(x));
Ok(v)
self.try_fold(C::default(), |mut acc, x| match x {
Ok(x) => {
acc.extend(std::iter::once(x));
Ok(acc)
}
Err(e) => Err(e),
})
}
}
Expand All @@ -62,6 +58,9 @@ pub struct GenericArgumentsCollector<'ast> {
}

impl<'ast> GenericArgumentsCollector<'ast> {
// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_type(ty: &'ast Type, filter: impl Into<Option<Vec<&'ast Ident>>>) -> Self {
let mut this = Self::default().with_filter(filter.into());

Expand All @@ -75,6 +74,9 @@ impl<'ast> GenericArgumentsCollector<'ast> {
this
}

// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_generics(
g: &'ast Generics,
filter: impl Into<Option<Vec<&'ast Ident>>>,
Expand Down Expand Up @@ -145,6 +147,9 @@ pub struct GenericParamsCollector<'ast> {
}

impl<'ast> GenericParamsCollector<'ast> {
// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_generics(generics: &'ast Generics) -> Self {
let mut this = Self::default();

Expand All @@ -153,6 +158,9 @@ impl<'ast> GenericParamsCollector<'ast> {
this
}

// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_type(ty: &'ast Type) -> Self {
let mut this = Self::default();

Expand Down Expand Up @@ -199,6 +207,9 @@ pub struct IdentsCollector<'ast> {
}

impl<'ast> IdentsCollector<'ast> {
// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_generics(generics: &'ast Generics) -> Self {
let mut this = Self::default();

Expand All @@ -207,6 +218,9 @@ impl<'ast> IdentsCollector<'ast> {
this
}

// allow it here as it is used in another
// macro code that gets compile when used?
#[allow(dead_code)]
pub fn traverse_type(ty: &'ast Type) -> Self {
let mut this = Self::default();

Expand Down
2 changes: 1 addition & 1 deletion bolos-mock/src/hash/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Keccak<const S: usize>(tiny_keccak::Keccak);
//This below is a workaround to allow to implement the functionality
// only for specific values of S

trait Keccak_<const S: usize>: Sized {
pub trait Keccak_<const S: usize>: Sized {
fn new() -> Result<Self, crate::Error>;
}

Expand Down
5 changes: 5 additions & 0 deletions bolos-mock/src/pic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ impl<T> PIC<T> {
}

impl PIC<()> {
/// This function is used to manually convert a pointer to a pic.
/// # Safety
/// This function is unsafe because it can create a PIC from any pointer.
/// but this mocking implementations is safe, we keep the unsafe part for compatibility
/// with the counterpart code that uses the real SDK
pub unsafe fn manual(ptr: usize) -> usize {
ptr
}
Expand Down
2 changes: 1 addition & 1 deletion bolos/src/flash_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const SLOT_SIZE: usize = PAGE_SIZE - COUNTER_SIZE - CRC_SIZE;

pub const ZEROED_STORAGE: [u8; PAGE_SIZE] = Slot::zeroed().as_storage();

pub(self) struct Slot<'nvm> {
struct Slot<'nvm> {
pub counter: u64,
payload: &'nvm [u8; SLOT_SIZE],
crc: u32,
Expand Down
4 changes: 2 additions & 2 deletions bolos/src/swapping_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl<'r, 'f, const RAM: usize, const FLASH: usize> SwappingBuffer<'r, 'f, RAM, F
pub fn read_exact(&self) -> &[u8] {
//cnt is guaranteed to be less than the slice len
match self.state {
BufferState::WritingToRam(cnt) => &self.ram.get(..cnt).ledger_unwrap(),
BufferState::WritingToFlash(cnt) => &self.flash.get(..cnt).ledger_unwrap(),
BufferState::WritingToRam(cnt) => self.ram.get(..cnt).ledger_unwrap(),
BufferState::WritingToFlash(cnt) => self.flash.get(..cnt).ledger_unwrap(),
}
}

Expand Down
12 changes: 6 additions & 6 deletions bolos/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::LedgerUnwrap;
macro_rules! show_ui {
($show:expr, $tx:ident) => {
match unsafe { $show } {
Ok((size, err)) if err == crate::ApduError::Success as u16 => {
Ok((size, err)) if err == $crate::ApduError::Success as u16 => {
*$tx = size as _;
Ok(())
}
Expand All @@ -36,24 +36,24 @@ macro_rules! show_ui {

match err.try_into() {
Ok(err) => Err(err),
Err(_) => Err(crate::ApduError::ExecutionError),
Err(_) => Err($crate::ApduError::ExecutionError),
}
}
Err(_) => Err(crate::ApduError::ExecutionError),
Err(_) => Err($crate::ApduError::ExecutionError),
}
};
($show:expr) => {
match unsafe { $show } {
Ok((size, err)) if err == crate::ApduError::Success as u16 => Ok(size as _),
Ok((size, err)) if err == $crate::ApduError::Success as u16 => Ok(size as _),
Ok((_, err)) => {
use ::core::convert::TryInto;

match err.try_into() {
Ok(err) => Err(err),
Err(_) => Err(crate::ApduError::ExecutionError),
Err(_) => Err($crate::ApduError::ExecutionError),
}
}
Err(_) => Err(crate::ApduError::ExecutionError),
Err(_) => Err($crate::ApduError::ExecutionError),
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion bolos/src/utils/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'apdu> ApduBufferRead<'apdu> {
pub fn payload(&self) -> Result<&[u8], ApduBufferReadError> {
let plen = self.inner[APDU_INDEX_LEN] as usize;
//check that the buffer is long enough for the payload
Self::check_min_len(self.inner.len(), plen as usize, APDU_MIN_LENGTH as usize)
Self::check_min_len(self.inner.len(), plen, APDU_MIN_LENGTH as usize)
.map_err(|err| err.length_to_payload())?;

Ok(&self.inner[APDU_MIN_LENGTH as usize..APDU_MIN_LENGTH as usize + plen])
Expand Down
7 changes: 6 additions & 1 deletion zemu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
#![no_std]
#![no_builtins]
#![allow(dead_code)]
// There are some exported types for which clippy complains
// that they are not used. But they are meant to be used by library users
// under specifict targets depending on feature flags, that are not defined
// globaly in this workspace.
#![allow(unused)]

#[macro_use]
extern crate cfg_if;

/// cbindgen:ignore
pub(self) mod bindings {
mod bindings {
extern "C" {
cfg_if! {
if #[cfg(zemu_sdk)] {
Expand Down
4 changes: 2 additions & 2 deletions zemu/src/ui_toolkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl<B: UIBackend<KS>, const KS: usize> Zui<B, KS> {
fn format_key_with_page(&mut self) {
if self.page_count > 1 {
let key = self.backend.key_buf();
let key_len = strlen(&key[..]).unwrap_or_else(|_| key.len());
let key_len = strlen(&key[..]).unwrap_or(key.len());

if key_len < KS {
let mut tmp = ArrayString::from_byte_string(key).expect("key was not utf8");
Expand Down Expand Up @@ -441,7 +441,7 @@ fn strlen(s: &[u8]) -> Result<usize, StrNotNullTerminated> {
}

/// This function returns the index of the first null byte if found
pub(self) fn c_strlen(s: *const u8, max: usize) -> Result<usize, StrNotNullTerminated> {
fn c_strlen(s: *const u8, max: usize) -> Result<usize, StrNotNullTerminated> {
let mut count = 0;
loop {
if count >= max {
Expand Down

0 comments on commit 46ea860

Please sign in to comment.