From 15eadb6110da3a2fcbd38016c0e3d3149a58b026 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Mon, 12 Sep 2022 16:04:23 +0200 Subject: [PATCH] Fix Linter Warnings (#103) --- examples/circ.rs | 8 ++--- src/front/c/mod.rs | 14 ++++---- src/front/c/term.rs | 2 +- src/front/datalog/parser.rs | 66 ++++++++++++++++++------------------- src/front/zsharp/term.rs | 2 +- src/ir/term/mod.rs | 6 ++-- src/ir/term/precomp.rs | 2 +- src/ir/term/ty.rs | 4 +-- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/circ.rs b/examples/circ.rs index c1ff7653..7037a22c 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -116,7 +116,7 @@ enum Backend { } arg_enum! { - #[derive(PartialEq, Debug)] + #[derive(PartialEq, Eq, Debug)] enum Language { Zsharp, Datalog, @@ -125,21 +125,21 @@ arg_enum! { } } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum DeterminedLanguage { Zsharp, Datalog, C, } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum CostModelType { Opa, Hycc, } arg_enum! { - #[derive(PartialEq, Debug)] + #[derive(PartialEq, Eq, Debug)] enum ProofAction { Count, Setup, diff --git a/src/front/c/mod.rs b/src/front/c/mod.rs index 793aa6f9..2a4ee9d0 100644 --- a/src/front/c/mod.rs +++ b/src/front/c/mod.rs @@ -327,10 +327,10 @@ impl CGen { if let Some((_, term_)) = fs.search(field) { Ok(term_.clone()) } else { - return Err(format!("No field '{}'", field)); + Err(format!("No field '{}'", field)) } } else { - return Err(format!("{} is not a struct", struct_)); + Err(format!("{} is not a struct", struct_)) } } @@ -342,10 +342,10 @@ impl CGen { let res = cterm(CTermData::CStruct(struct_ty.clone(), new_fs.clone())); Ok(res) } else { - return Err(format!("No field '{}'", field)); + Err(format!("No field '{}'", field)) } } else { - return Err(format!("{} is not a struct", struct_)); + Err(format!("{} is not a struct", struct_)) } } @@ -509,18 +509,18 @@ impl CGen { self.array_store(old_inner, idx, val) } CLoc::Member(l, field) => { - let inner_loc = &*l.loc(); + let inner_loc = l.loc().clone(); let base = self .circ .get_value(inner_loc.clone()) .map_err(|e| format!("{}", e))? .unwrap_term(); let old_inner = self.field_select(&base, &field)?; - let new_inner = self.rebuild_lval(old_inner, *l.clone(), val)?; + let new_inner = self.rebuild_lval(old_inner, *l, val)?; let res = self.field_store(base, &field, new_inner); Ok(self .circ - .assign(inner_loc.clone(), Val::Term(res.unwrap())) + .assign(inner_loc, Val::Term(res.unwrap())) .map_err(|e| format!("{}", e))? .unwrap_term()) } diff --git a/src/front/c/term.rs b/src/front/c/term.rs index 4c773e6d..216d0bde 100644 --- a/src/front/c/term.rs +++ b/src/front/c/term.rs @@ -595,7 +595,7 @@ impl Embeddable for Ct { Ty::Array(n, _, ty) => { assert!(precompute.is_none()); let v: Vec = (0..*n) - .map(|i| self.declare_input(ctx, &*ty, idx_name(&name, i), visibility, None)) + .map(|i| self.declare_input(ctx, ty, idx_name(&name, i), visibility, None)) .collect(); let mut mem = ctx.mem.borrow_mut(); let id = mem.zero_allocate(*n, 32, ty.num_bits()); diff --git a/src/front/datalog/parser.rs b/src/front/datalog/parser.rs index 3796ea1e..da01f004 100644 --- a/src/front/datalog/parser.rs +++ b/src/front/datalog/parser.rs @@ -26,7 +26,7 @@ pub mod ast { span.as_str() } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::decimal_literal))] pub struct DecimalLiteral<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -35,7 +35,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::boolean_literal))] pub struct BooleanLiteral<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -44,7 +44,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::hex_literal))] pub struct HexLiteral<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -53,7 +53,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::bin_literal))] pub struct BinLiteral<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -62,7 +62,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::literal))] pub enum Literal<'ast> { DecimalLiteral(DecimalLiteral<'ast>), @@ -82,7 +82,7 @@ pub mod ast { } } - #[derive(Debug, PartialEq, FromPest, Clone)] + #[derive(Debug, PartialEq, Eq, FromPest, Clone)] #[pest_ast(rule(Rule::un_op))] pub enum UnaryOperator<'ast> { Not(Not<'ast>), @@ -90,26 +90,26 @@ pub mod ast { Neg(Neg<'ast>), } - #[derive(Debug, PartialEq, FromPest, Clone)] + #[derive(Debug, PartialEq, Eq, FromPest, Clone)] #[pest_ast(rule(Rule::not))] pub struct Not<'ast> { #[pest_ast(outer())] pub span: Span<'ast>, } - #[derive(Debug, PartialEq, FromPest, Clone)] + #[derive(Debug, PartialEq, Eq, FromPest, Clone)] #[pest_ast(rule(Rule::bitnot))] pub struct BitNot<'ast> { #[pest_ast(outer())] pub span: Span<'ast>, } - #[derive(Debug, PartialEq, FromPest, Clone)] + #[derive(Debug, PartialEq, Eq, FromPest, Clone)] #[pest_ast(rule(Rule::neg))] pub struct Neg<'ast> { #[pest_ast(outer())] pub span: Span<'ast>, } - #[derive(Debug, PartialEq, Clone)] + #[derive(Debug, PartialEq, Eq, Clone)] pub enum BinaryOperator { BitXor, BitAnd, @@ -155,7 +155,7 @@ pub mod ast { ]) } - #[derive(Debug, PartialEq, Clone)] + #[derive(Debug, PartialEq, Eq, Clone)] pub enum Expression<'ast> { Binary(BinaryExpression<'ast>), Identifier(Ident<'ast>), @@ -166,7 +166,7 @@ pub mod ast { Paren(Box>, Span<'ast>), } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::identifier))] pub struct Ident<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -175,7 +175,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::call_expr))] pub struct CallExpression<'ast> { pub fn_name: Ident<'ast>, @@ -184,7 +184,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::access_expr))] pub struct AccessExpression<'ast> { pub arr: Ident<'ast>, @@ -193,7 +193,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, PartialEq, Clone)] + #[derive(Debug, PartialEq, Eq, Clone)] pub struct BinaryExpression<'ast> { pub op: BinaryOperator, pub left: Box>, @@ -201,7 +201,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::unary_expression))] pub struct UnaryExpression<'ast> { pub op: UnaryOperator<'ast>, @@ -363,7 +363,7 @@ pub mod ast { }) } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::ty_uint))] pub struct TypeUint<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -372,7 +372,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::ty_bool))] pub struct TypeBool<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -381,7 +381,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::ty_field))] pub struct TypeField<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -390,7 +390,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::base_ty))] pub enum BaseType<'ast> { Uint(TypeUint<'ast>), @@ -408,7 +408,7 @@ pub mod ast { } } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::ty))] pub struct Type<'ast> { pub base: BaseType<'ast>, @@ -417,7 +417,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::vis_public))] pub struct Public<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -426,7 +426,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::vis_private))] pub struct Private<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -435,7 +435,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::vis))] pub enum Visibility<'ast> { Public(Public<'ast>), @@ -451,7 +451,7 @@ pub mod ast { } } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::qual_ty))] pub struct QualType<'ast> { pub qualifier: Option>, @@ -460,7 +460,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::decl))] pub struct Declaration<'ast> { pub ident: Ident<'ast>, @@ -469,7 +469,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::dec))] pub struct Decreasing<'ast> { #[pest_ast(outer(with(span_into_str)))] @@ -478,7 +478,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::fn_arg_decl))] pub struct ArgDeclaration<'ast> { pub dec: Option>, @@ -488,7 +488,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::exist_prefix))] pub struct Existential<'ast> { pub declarations: Vec>, @@ -496,7 +496,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::condition))] pub struct Condition<'ast> { pub existential: Option>, @@ -505,7 +505,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::rule))] pub struct Rule_<'ast> { pub name: Ident<'ast>, @@ -515,7 +515,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::program))] pub struct Program<'ast> { pub rules: Vec>, @@ -524,7 +524,7 @@ pub mod ast { pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] + #[derive(Debug, FromPest, PartialEq, Eq, Clone)] #[pest_ast(rule(Rule::EOI))] pub struct EOI; } diff --git a/src/front/zsharp/term.rs b/src/front/zsharp/term.rs index c8393dcd..daefeb51 100644 --- a/src/front/zsharp/term.rs +++ b/src/front/zsharp/term.rs @@ -948,7 +948,7 @@ impl Embeddable for ZSharp { debug_assert_eq!(*n, ps.len()); array( ps.into_iter().enumerate().map(|(i, p)| { - self.declare_input(ctx, &*ty, idx_name(&name, i), visibility, p) + self.declare_input(ctx, ty, idx_name(&name, i), visibility, p) }), ) .unwrap() diff --git a/src/ir/term/mod.rs b/src/ir/term/mod.rs index eef29e34..a06def93 100644 --- a/src/ir/term/mod.rs +++ b/src/ir/term/mod.rs @@ -744,7 +744,7 @@ pub enum Value { Tuple(Box<[Value]>), } -#[derive(Clone, PartialEq, Debug, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug, PartialOrd, Hash, Serialize, Deserialize)] /// An IR array value. /// /// A sized, space array. @@ -1790,7 +1790,7 @@ impl std::iter::Iterator for PostOrderIter { /// A party identifier pub type PartyId = u8; -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] /// An IR constraint system. pub struct ComputationMetadata { /// A map from party names to numbers assigned to them. @@ -1952,7 +1952,7 @@ impl Display for ComputationMetadata { } } -#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] /// An IR computation. pub struct Computation { /// The outputs of the computation. diff --git a/src/ir/term/precomp.rs b/src/ir/term/precomp.rs index cad4b568..54a94acc 100644 --- a/src/ir/term/precomp.rs +++ b/src/ir/term/precomp.rs @@ -10,7 +10,7 @@ use crate::ir::term::*; /// A "precomputation". /// /// Expresses a computation to be run in advance by a single party. -#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct PreComp { /// A map from output names to the terms that compute them. outputs: FxHashMap, diff --git a/src/ir/term/ty.rs b/src/ir/term/ty.rs index 3d463986..bc366e22 100644 --- a/src/ir/term/ty.rs +++ b/src/ir/term/ty.rs @@ -520,7 +520,7 @@ fn int_or<'a>(a: &'a Sort, ctx: &'static str) -> Result<&'a Sort, TypeErrorReaso fn array_or<'a>(a: &'a Sort, ctx: &'static str) -> Result<(&'a Sort, &'a Sort), TypeErrorReason> { if let Sort::Array(k, v, _) = a { - Ok((&*k, &*v)) + Ok((k, v)) } else { Err(TypeErrorReason::ExpectedArray(a.clone(), ctx)) } @@ -531,7 +531,7 @@ fn arrmap_or<'a>( ctx: &'static str, ) -> Result<(&'a Sort, &'a Sort, &'a usize), TypeErrorReason> { if let Sort::Array(k, v, s) = a { - Ok((&*k, &*v, &*s)) + Ok((k, v, s)) } else { Err(TypeErrorReason::ExpectedArray(a.clone(), ctx)) }