Ver Fonte

zkas: Clippy lints.

Luther Blissett há 4 anos atrás
pai
commit
acc5773230
7 ficheiros alterados com 11 adições e 11 exclusões
  1. 1 1
      bin/zkas/src/main.rs
  2. 2 1
      src/zk/vm.rs
  3. 1 0
      src/zkas/analyzer.rs
  4. 1 1
      src/zkas/compiler.rs
  5. 1 0
      src/zkas/decoder.rs
  6. 1 4
      src/zkas/error.rs
  7. 4 4
      src/zkas/parser.rs

+ 1 - 1
bin/zkas/src/main.rs

@@ -51,7 +51,7 @@ fn main() {
     };
 
     // Clean up tabs, and convert CRLF to LF.
-    let source = source.replace("\t", "    ").replace("\r\n", "\n");
+    let source = source.replace('\t', "    ").replace("\r\n", "\n");
 
     // The lexer goes over the input file and separates its content into
     // tokens that get fed into a parser.

+ 2 - 1
src/zk/vm.rs

@@ -97,6 +97,7 @@ pub struct ZkCircuit {
 impl ZkCircuit {
     pub fn new(witnesses: Vec<Witness>, circuit_code: ZkBinary) -> Self {
         let constants = circuit_code.constants.iter().map(|x| x.1.clone()).collect();
+        #[allow(clippy::map_clone)]
         let literals = circuit_code.literals.iter().map(|x| x.clone()).collect();
         Self { constants, witnesses, literals, opcodes: circuit_code.opcodes }
     }
@@ -341,7 +342,7 @@ impl Circuit<pallas::Base> for ZkCircuit {
         // N.B. Only uint64 is supported right now.
         for literal in &self.literals {
             match literal.0 {
-                LitType::Uint64 => match u64::from_str_radix(&literal.1, 10) {
+                LitType::Uint64 => match literal.1.parse::<u64>() {
                     Ok(v) => litstack.push(v),
                     Err(e) => {
                         error!("Failed converting u64 literal: {}", e);

+ 1 - 0
src/zkas/analyzer.rs

@@ -74,6 +74,7 @@ impl Analyzer {
             }
 
             // Edge-cases for some opcodes
+            #[allow(clippy::single_match)]
             match &statement.opcode {
                 Opcode::RangeCheck => {
                     if let Arg::Lit(arg0) = &statement.rhs[0] {

+ 1 - 1
src/zkas/compiler.rs

@@ -142,7 +142,7 @@ impl Compiler {
 
     fn lookup_literal(literals: &[Literal], name: &str) -> Option<usize> {
         for (idx, n) in literals.iter().enumerate() {
-            if &n.name == &name {
+            if n.name == name {
                 return Some(idx)
             }
         }

+ 1 - 0
src/zkas/decoder.rs

@@ -155,6 +155,7 @@ impl ZkBinary {
         Ok(witnesses)
     }
 
+    #[allow(clippy::type_complexity)]
     fn parse_circuit(bytes: &[u8]) -> Result<Vec<(Opcode, Vec<(StackType, usize)>)>> {
         let mut opcodes = vec![];
 

+ 1 - 4
src/zkas/error.rs

@@ -15,10 +15,7 @@ impl ErrorEmitter {
 
     fn fmt(&self, msg: String, ln: usize, col: usize) -> String {
         let (err_msg, dbg_msg, caret) = match ln {
-            0 => {
-                let err_msg = format!("{}", msg);
-                (err_msg, "".to_string(), "".to_string())
-            }
+            0 => (msg, "".to_string(), "".to_string()),
             _ => {
                 let err_msg = format!("{} (line {}, column {})", msg, ln, col);
                 let dbg_msg = format!("{}:{}:{}: {}", self.file, ln, col, self.lines[ln - 1]);

+ 4 - 4
src/zkas/parser.rs

@@ -170,7 +170,7 @@ impl Parser {
                     constants_map.insert(name.token.clone(), (name.clone(), typ.clone()));
                 }
 
-                if let Some(_) = constant_inner.next() {
+                if constant_inner.next().is_some() {
                     self.error.abort("Internal error, leftovers in 'constant' iterator", 0, 0);
                 }
 
@@ -211,7 +211,7 @@ impl Parser {
                     witnesses_map.insert(name.token.clone(), (name.clone(), typ.clone()));
                 }
 
-                if let Some(_) = contract_inner.next() {
+                if contract_inner.next().is_some() {
                     self.error.abort("Internal error, leftovers in 'contract' iterator", 0, 0);
                 }
 
@@ -672,7 +672,7 @@ impl Parser {
                 let func_name = token.token.as_str();
 
                 // TODO: MAKE SURE IT'S A SYMBOL
-                if let Some(op) = Opcode::from_name(&func_name) {
+                if let Some(op) = Opcode::from_name(func_name) {
                     let rhs = self.parse_function_call(token, &mut iter);
                     stmt.opcode = op;
                     stmt.rhs = rhs;
@@ -777,7 +777,7 @@ impl Parser {
 
                     TokenType::Number => {
                         // Check if we can actually convert this into a number.
-                        match u64::from_str_radix(&arg.token, 10) {
+                        match arg.token.parse::<u64>() {
                             Ok(_) => {}
                             Err(e) => {
                                 self.error.abort(