From 72c3705eab4f3cedf84f47c3e76bc191d909895f Mon Sep 17 00:00:00 2001 From: Fredrik Dahlgren Date: Thu, 20 Jun 2024 17:23:24 +0200 Subject: [PATCH] Fixed Clippy lints --- parser/src/include_logic.rs | 2 +- parser/src/syntax_sugar_remover.rs | 2 +- program_analysis/src/analysis_runner.rs | 8 ++++---- program_structure/src/program_library/report.rs | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/parser/src/include_logic.rs b/parser/src/include_logic.rs index ac28318..9630ef7 100644 --- a/parser/src/include_logic.rs +++ b/parser/src/include_logic.rs @@ -120,7 +120,7 @@ impl FileStack { } else { // only match include paths with a single component i.e. lib.circom and not dir/lib.circom or // ./lib.circom - if include.path.find(std::path::MAIN_SEPARATOR) == None { + if include.path.find(std::path::MAIN_SEPARATOR).is_none() { debug!("checking if `{}` matches `{}`", include.path, lib.path.display()); if lib.path.file_name().expect("good library file") == pathos { debug!("adding include `{}` from file", lib.path.display()); diff --git a/parser/src/syntax_sugar_remover.rs b/parser/src/syntax_sugar_remover.rs index 6fa83f5..19437d8 100644 --- a/parser/src/syntax_sugar_remover.rs +++ b/parser/src/syntax_sugar_remover.rs @@ -452,7 +452,7 @@ fn remove_anonymous_from_expression( } } } else { - new_signals = signals.clone(); + new_signals.clone_from(&signals); for _ in 0..signals.len() { new_operators.push(AssignOp::AssignConstraintSignal); } diff --git a/program_analysis/src/analysis_runner.rs b/program_analysis/src/analysis_runner.rs index 1abb656..548094d 100644 --- a/program_analysis/src/analysis_runner.rs +++ b/program_analysis/src/analysis_runner.rs @@ -217,7 +217,7 @@ impl AnalysisRunner { fn cache_template(&mut self, name: &str) -> Result<&Cfg, AnalysisError> { if !self.template_cfgs.contains_key(name) { // The template CFG needs to be generated from the AST. - if self.template_reports.get(name).is_some() { + if self.template_reports.contains_key(name) { // We have already failed to generate the CFG. return Err(AnalysisError::FailedToLiftTemplate { name: name.to_string() }); } @@ -243,7 +243,7 @@ impl AnalysisRunner { fn cache_function(&mut self, name: &str) -> Result<&Cfg, AnalysisError> { if !self.function_cfgs.contains_key(name) { // The function CFG needs to be generated from the AST. - if self.function_reports.get(name).is_some() { + if self.function_reports.contains_key(name) { // We have already failed to generate the CFG. return Err(AnalysisError::FailedToLiftFunction { name: name.to_string() }); } @@ -289,11 +289,11 @@ impl AnalysisRunner { impl AnalysisContext for AnalysisRunner { fn is_template(&self, name: &str) -> bool { - self.template_asts.get(name).is_some() + self.template_asts.contains_key(name) } fn is_function(&self, name: &str) -> bool { - self.function_asts.get(name).is_some() + self.function_asts.contains_key(name) } fn template(&mut self, name: &str) -> Result<&Cfg, AnalysisError> { diff --git a/program_structure/src/program_library/report.rs b/program_structure/src/program_library/report.rs index 3a4816d..df5aee8 100644 --- a/program_structure/src/program_library/report.rs +++ b/program_structure/src/program_library/report.rs @@ -1,5 +1,6 @@ use anyhow::anyhow; use std::cmp::Ordering; +use std::fmt::Display; use std::str::FromStr; use codespan_reporting::diagnostic::{Diagnostic, Label}; @@ -44,15 +45,14 @@ impl Ord for MessageCategory { } } -impl ToString for MessageCategory { - fn to_string(&self) -> String { +impl Display for MessageCategory { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use MessageCategory::*; match self { - Error => "error", - Warning => "warning", - Info => "info", + Error => write!(f, "error"), + Warning => write!(f, "warning"), + Info => write!(f, "info"), } - .to_string() } }