Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco Bloemen committed Aug 17, 2020
1 parent 53f57e8 commit 645f7bd
Show file tree
Hide file tree
Showing 33 changed files with 184 additions and 71 deletions.
15 changes: 11 additions & 4 deletions algebra/elliptic-curve/src/curve.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{ScalarFieldElement, BETA};
use serde::{Deserialize, Serialize};
use std::{
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
prelude::v1::*,
};
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use zkp_primefield::{FieldElement, NegInline, One, Zero};
use zkp_u256::{commutative_binop, noncommutative_binop};

Expand Down Expand Up @@ -139,6 +142,8 @@ impl AddAssign<&Affine> for Affine {
macro_rules! curve_operations {
($type:ident) => {
impl SubAssign<&$type> for $type {
// Subtraction suspiciously involves addition
#[allow(clippy::suspicious_op_assign_impl)]
fn sub_assign(&mut self, rhs: &Self) {
*self += &rhs.neg()
}
Expand All @@ -147,6 +152,8 @@ macro_rules! curve_operations {
impl Mul<&ScalarFieldElement> for &$type {
type Output = $type;

// We need to do a bit of math here
#[allow(clippy::suspicious_arithmetic_impl)]
fn mul(self, scalar: &ScalarFieldElement) -> $type {
use zkp_u256::Binary;
let bits = scalar.to_uint();
Expand Down
11 changes: 7 additions & 4 deletions algebra/elliptic-curve/src/jacobian.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{curve_operations, Affine, ScalarFieldElement};
use std::{
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
prelude::v1::*,
};
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use zkp_macros_decl::field_element;
use zkp_primefield::{FieldElement, Inv, NegInline, One, SquareInline, Zero};
use zkp_u256::{commutative_binop, noncommutative_binop, U256};
Expand Down
1 change: 1 addition & 0 deletions algebra/elliptic-curve/src/scalar_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl Parameters for Order {
#[cfg(test)]
mod tests {
use super::*;
use zkp_primefield::{One, Pow, Zero};

const PRIME_FACTORS: [U256; 5] = [
u256h!("02"),
Expand Down
7 changes: 6 additions & 1 deletion algebra/elliptic-curve/src/wnaf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{curve::Affine, jacobian::Jacobian, ScalarFieldElement};
use itertools::izip;
use std::prelude::v1::*;
use zkp_primefield::{FieldElement, Inv, One, SquareInline};
use zkp_u256::{Binary, U256};

Expand Down
9 changes: 8 additions & 1 deletion algebra/primefield/src/fft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
// Many false positives from trait bounds
#![allow(single_use_lifetimes)]

// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

mod bit_reverse;
mod prefetch;
mod recursive;
Expand All @@ -18,7 +24,6 @@ use log::trace;
use rayon::{current_num_threads, prelude::*};
#[cfg(feature = "rayon")]
use std::cmp::max;
use std::prelude::v1::*;

// Re-exports
// TODO: Only re-export for bench
Expand Down Expand Up @@ -192,6 +197,8 @@ mod tests {
// O(n^2) reference implementation evaluating
// x_i' = Sum_j x_j * omega_n^(ij)
// directly using Horner's method.
// False positive
#[allow(clippy::same_item_push)]
fn reference_fft(x: &[FieldElement], inverse: bool) -> Vec<FieldElement> {
let mut root = FieldElement::root(x.len()).unwrap();
if inverse {
Expand Down
8 changes: 7 additions & 1 deletion algebra/primefield/src/geometric_series.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// False positives, see <https://github.com/rust-lang/rust/issues/55058>
#![allow(single_use_lifetimes)]

// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{FieldLike, Pow, RefFieldLike};
use std::{cmp::min, prelude::v1::*};
use std::cmp::min;

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand Down
8 changes: 7 additions & 1 deletion algebra/primefield/src/invert_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
#![allow(clippy::module_name_repetitions)]
// Many false positives from trait bounds
#![allow(single_use_lifetimes)]
use crate::{FieldLike, Inv, RefFieldLike};

// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{FieldLike, Inv, RefFieldLike};

pub fn invert_batch_src_dst<Field>(source: &[Field], destination: &mut [Field])
where
Field: FieldLike + From<usize> + std::fmt::Debug,
Expand Down
4 changes: 4 additions & 0 deletions algebra/primefield/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ impl<P: Parameters> Neg for &PrimeField<P> {
}

impl<P: Parameters> DivAssign<&Self> for PrimeField<P> {
// Division suspiciously requires multiplication
#[allow(clippy::suspicious_op_assign_impl)]
#[inline(always)]
fn div_assign(&mut self, rhs: &Self) {
*self *= rhs.inv().expect("Division by zero")
}
}

impl<P: Parameters> DivAssign<Self> for PrimeField<P> {
// Division suspiciously requires multiplication
#[allow(clippy::suspicious_op_assign_impl)]
#[inline(always)]
fn div_assign(&mut self, rhs: Self) {
*self *= rhs.inv().expect("Division by zero")
Expand Down
7 changes: 6 additions & 1 deletion algebra/primefield/src/prime_field.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{Root, SquareRoot, UInt as FieldUInt};
#[cfg(feature = "std")]
use std::fmt;
use std::{
hash::{Hash, Hasher},
marker::PhantomData,
ops::Shr,
prelude::v1::*,
};
use zkp_u256::{
AddInline, Binary, DivRem, Inv, Montgomery as _, MontgomeryParameters, MulInline, NegInline,
Expand Down
11 changes: 7 additions & 4 deletions algebra/u256/src/additive.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{
adc, assign_ops_from_trait, noncommutative_self_ops_from_trait, sbb, self_ops_from_trait,
AddFullInline, AddInline, NegInline, SubFromFullInline, SubFromInline, SubFullInline,
SubInline, U256,
};
use std::{
ops::{Add, AddAssign, Neg, Sub, SubAssign},
prelude::v1::*,
};
use std::ops::{Add, AddAssign, Neg, Sub, SubAssign};

// Additive operations: Add, Sub

Expand Down
7 changes: 6 additions & 1 deletion algebra/u256/src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{commutative_binop, traits::Binary, U256};
use std::{
ops::{
BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Shl, ShlAssign, Shr,
ShrAssign,
},
prelude::v1::*,
u64,
};

Expand Down
10 changes: 7 additions & 3 deletions algebra/u256/src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::U256;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{prelude::v1::*, u64};
use std::u64;

impl U256 {
pub fn from_bytes_be(n: &[u8; 32]) -> Self {
Expand Down Expand Up @@ -159,10 +165,8 @@ impl U256 {
#[cfg(test)]
mod tests {
use super::*;
use bincode;
use num_traits::identities::One;
use proptest::prelude::*;
use serde_json;

#[test]
fn test_one() {
Expand Down
7 changes: 6 additions & 1 deletion algebra/u256/src/division.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{
algorithms::{div_2_1, divrem_nby1, divrem_nbym, inv_mod},
noncommutative_binop, Binary, DivRem, InvMod, U256,
Expand All @@ -6,7 +12,6 @@ use num_traits::Inv;
use std::{
num::Wrapping,
ops::{Div, DivAssign, Rem, RemAssign},
prelude::v1::*,
u64,
};

Expand Down
7 changes: 6 additions & 1 deletion algebra/u256/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::U256;
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::U256;

#[cfg(feature = "std")]
use std::{fmt, format};

Expand Down
10 changes: 9 additions & 1 deletion algebra/u256/src/multiplicative.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{
algorithms::{adc, divrem_nby1, divrem_nbym, mac},
assign_ops_from_trait, self_ops_from_trait, MulFullInline, MulInline, SquareFullInline,
Expand All @@ -6,7 +12,6 @@ use crate::{
use num_traits::Pow;
use std::{
ops::{Mul, MulAssign},
prelude::v1::*,
u64,
};

Expand Down Expand Up @@ -238,6 +243,9 @@ impl core::iter::Product for U256 {

// TODO: Replace literals with u256h!
#[allow(clippy::unreadable_literal)]
// TODO: Better names
#[allow(clippy::similar_names)]
#[allow(clippy::clippy::many_single_char_names)]
#[cfg(test)]
mod tests {
use super::*;
Expand Down
8 changes: 7 additions & 1 deletion algebra/u256/src/u256.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

#[cfg(any(test, feature = "proptest"))]
use proptest_derive::Arbitrary;
use std::{cmp::Ordering, prelude::v1::*, u64};
use std::{cmp::Ordering, u64};

#[derive(PartialEq, Eq, Clone, Default, Hash)]
// TODO: Generate a quasi-random sequence.
Expand Down
2 changes: 2 additions & 0 deletions crypto/elliptic-curve-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
// #![allow(clippy::missing_errors_doc)]
// TODO: Add `must_use` attributes
#![allow(clippy::must_use_candidate)]
// TODO: False positives <https://github.com/rust-lang/rust-clippy/issues/5917>
#![allow(clippy::wildcard_imports)]

mod private_key;
mod public_key;
Expand Down
2 changes: 1 addition & 1 deletion crypto/elliptic-curve-crypto/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl From<Affine> for PublicKey {
#[cfg(test)]
mod tests {
use super::*;
use u256::U256;
use zkp_macros_decl::{field_element, u256h};
use zkp_primefield::FieldElement;
use zkp_u256::U256;

#[test]
fn test_pubkey() {
Expand Down
3 changes: 0 additions & 3 deletions crypto/hash/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "std")]
use hex;

#[cfg(feature = "std")]
use std::fmt;

Expand Down
7 changes: 6 additions & 1 deletion crypto/hash/src/hashable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{hash::Hash, masked_keccak::MaskedKeccak};
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{hash::Hash, masked_keccak::MaskedKeccak};
use zkp_primefield::FieldElement;
use zkp_u256::U256;

Expand Down
7 changes: 6 additions & 1 deletion crypto/merkle-tree/src/commitment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{Error, Index, Result};
use itertools::Itertools;
use std::prelude::v1::*;
use zkp_error_utils::require;
use zkp_hash::Hash;

Expand Down
8 changes: 7 additions & 1 deletion crypto/merkle-tree/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{Commitment, Error, Index, Node, Result};
use itertools::Itertools;
use std::{collections::VecDeque, prelude::v1::*};
use std::collections::VecDeque;
use zkp_error_utils::require;
use zkp_hash::{Hash, Hashable};

Expand Down
3 changes: 3 additions & 0 deletions crypto/merkle-tree/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub enum Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// False positive
#[allow(clippy::useless_attribute)]
#[allow(clippy::enum_glob_use)]
use Error::*;
match *self {
TreeToLarge => write!(f, "Tree too large"),
Expand Down
7 changes: 6 additions & 1 deletion crypto/merkle-tree/src/vector_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{Commitment, Result, Tree};
// False positive: attribute has a use
#[allow(clippy::useless_attribute)]
// False positive: Importing preludes is allowed
#[allow(clippy::wildcard_imports)]
use std::prelude::v1::*;

use crate::{Commitment, Result, Tree};
use zkp_hash::{Hash, Hashable};

#[cfg(feature = "mmap")]
Expand Down
1 change: 0 additions & 1 deletion crypto/stark/examples/large_fib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::all)]
use env_logger;
use log::info;
use std::{env, time::Instant};
use zkp_macros_decl::field_element;
Expand Down
Loading

0 comments on commit 645f7bd

Please sign in to comment.