Fix most Clippy warnings.

This commit is contained in:
Guillaume Endignoux
2020-09-23 16:21:20 +02:00
parent 616476ac43
commit 5511811703
8 changed files with 16 additions and 5 deletions

View File

@@ -554,6 +554,7 @@ impl Add for &Int256 {
type Output = (Int256, Digit); type Output = (Int256, Digit);
// Returns sum and carry (0 or 1). // Returns sum and carry (0 or 1).
#[allow(clippy::suspicious_arithmetic_impl)]
fn add(self, other: &Int256) -> (Int256, Digit) { fn add(self, other: &Int256) -> (Int256, Digit) {
let mut digits = [0; NDIGITS]; let mut digits = [0; NDIGITS];
let mut carry: DoubleDigit = 0; let mut carry: DoubleDigit = 0;
@@ -570,6 +571,7 @@ impl Add for &Int256 {
impl AddAssign<&Int256> for Int256 { impl AddAssign<&Int256> for Int256 {
// Adds to self, ignoring carry. // Adds to self, ignoring carry.
#[allow(clippy::suspicious_op_assign_impl)]
fn add_assign(&mut self, other: &Int256) { fn add_assign(&mut self, other: &Int256) {
let mut carry: DoubleDigit = 0; let mut carry: DoubleDigit = 0;
for i in 0..NDIGITS { for i in 0..NDIGITS {
@@ -584,6 +586,7 @@ impl Add<Digit> for &Int256 {
type Output = (Int256, Digit); type Output = (Int256, Digit);
// Returns sum and carry (0 or 1). // Returns sum and carry (0 or 1).
#[allow(clippy::suspicious_arithmetic_impl)]
fn add(self, digit: Digit) -> (Int256, Digit) { fn add(self, digit: Digit) -> (Int256, Digit) {
let mut digits = [0; NDIGITS]; let mut digits = [0; NDIGITS];
let mut carry = digit as DoubleDigit; let mut carry = digit as DoubleDigit;
@@ -603,6 +606,7 @@ impl Sub for &Int256 {
type Output = (Int256, Digit); type Output = (Int256, Digit);
// Returns difference and borrow (0 or -1). // Returns difference and borrow (0 or -1).
#[allow(clippy::suspicious_arithmetic_impl)]
fn sub(self, other: &Int256) -> (Int256, Digit) { fn sub(self, other: &Int256) -> (Int256, Digit) {
let mut digits = [0; NDIGITS]; let mut digits = [0; NDIGITS];
let mut borrow: SignedDoubleDigit = 0; let mut borrow: SignedDoubleDigit = 0;
@@ -620,6 +624,7 @@ impl Sub for &Int256 {
impl SubAssign<&Int256> for Int256 { impl SubAssign<&Int256> for Int256 {
// Substract from self, ignoring carry. // Substract from self, ignoring carry.
#[allow(clippy::suspicious_op_assign_impl)]
fn sub_assign(&mut self, other: &Int256) { fn sub_assign(&mut self, other: &Int256) {
let mut borrow: SignedDoubleDigit = 0; let mut borrow: SignedDoubleDigit = 0;
for i in 0..NDIGITS { for i in 0..NDIGITS {

View File

@@ -325,7 +325,7 @@ impl TryFrom<cbor::Value> for AuthenticatorClientPinParameters {
let key_agreement = key_agreement let key_agreement = key_agreement
.map(extract_map) .map(extract_map)
.transpose()? .transpose()?
.map(|x| CoseKey(x)); .map(CoseKey);
let pin_auth = pin_auth.map(extract_byte_string).transpose()?; let pin_auth = pin_auth.map(extract_byte_string).transpose()?;
let new_pin_enc = new_pin_enc.map(extract_byte_string).transpose()?; let new_pin_enc = new_pin_enc.map(extract_byte_string).transpose()?;
let pin_hash_enc = pin_hash_enc.map(extract_byte_string).transpose()?; let pin_hash_enc = pin_hash_enc.map(extract_byte_string).transpose()?;

View File

@@ -694,7 +694,7 @@ where
key_id: credential.credential_id.clone(), key_id: credential.credential_id.clone(),
transports: None, // You can set USB as a hint here. transports: None, // You can set USB as a hint here.
}; };
let user = if (flags & UV_FLAG != 0) && (credential.user_handle.len() > 0) { let user = if (flags & UV_FLAG != 0) && !credential.user_handle.is_empty() {
Some(PublicKeyCredentialUserEntity { Some(PublicKeyCredentialUserEntity {
user_id: credential.user_handle.clone(), user_id: credential.user_handle.clone(),
user_name: None, user_name: None,

View File

@@ -88,6 +88,7 @@ const _DEFAULT_MIN_PIN_LENGTH_RP_IDS: Vec<String> = Vec::new();
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
const _MAX_RP_IDS_LENGTH: usize = 8; const _MAX_RP_IDS_LENGTH: usize = 8;
#[allow(clippy::enum_variant_names)]
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]
enum Key { enum Key {
// TODO(cretin): Test whether this doesn't consume too much memory. Otherwise, we can use less // TODO(cretin): Test whether this doesn't consume too much memory. Otherwise, we can use less
@@ -406,10 +407,11 @@ impl PersistentStore {
data: pin_hash, data: pin_hash,
sensitive: true, sensitive: true,
}; };
Ok(match self.store.find_one(&Key::PinHash) { match self.store.find_one(&Key::PinHash) {
None => self.store.insert(entry)?, None => self.store.insert(entry)?,
Some((index, _)) => self.store.replace(index, entry)?, Some((index, _)) => self.store.replace(index, entry)?,
}) }
Ok(())
} }
pub fn pin_retries(&self) -> Result<u8, Ctap2StatusCode> { pub fn pin_retries(&self) -> Result<u8, Ctap2StatusCode> {

View File

@@ -44,6 +44,7 @@ impl TockAllocator {
} }
unsafe impl GlobalAlloc for TockAllocator { unsafe impl GlobalAlloc for TockAllocator {
#[allow(clippy::let_and_return)]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let ptr = HEAP let ptr = HEAP
.allocate_first_fit(layout) .allocate_first_fit(layout)

View File

@@ -25,6 +25,7 @@ pub struct Console {
} }
impl Console { impl Console {
#[allow(clippy::new_without_default)]
pub fn new() -> Console { pub fn new() -> Console {
Console { Console {
allow_buffer: [0; BUFFER_SIZE], allow_buffer: [0; BUFFER_SIZE],

View File

@@ -41,5 +41,5 @@ pub fn fill_buffer(buf: &mut [u8]) -> bool {
} }
util::yieldk_for(|| is_filled.get()); util::yieldk_for(|| is_filled.get());
return true; true
} }

View File

@@ -173,6 +173,7 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus {
// Same as recv, but with a timeout. // Same as recv, but with a timeout.
// If the timeout elapses, return None. // If the timeout elapses, return None.
#[allow(clippy::let_and_return)]
pub fn recv_with_timeout( pub fn recv_with_timeout(
buf: &mut [u8; 64], buf: &mut [u8; 64],
timeout_delay: Duration<isize>, timeout_delay: Duration<isize>,
@@ -199,6 +200,7 @@ pub fn recv_with_timeout(
// Same as send_or_recv, but with a timeout. // Same as send_or_recv, but with a timeout.
// If the timeout elapses, return None. // If the timeout elapses, return None.
#[allow(clippy::let_and_return)]
pub fn send_or_recv_with_timeout( pub fn send_or_recv_with_timeout(
buf: &mut [u8; 64], buf: &mut [u8; 64],
timeout_delay: Duration<isize>, timeout_delay: Duration<isize>,