From f28020c5ebc455e6889dfb048bc03f8128ad16dc Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 4 Jan 2024 03:06:44 +0100 Subject: [PATCH] chore: clippies and such --- src/artifact_output/mod.rs | 1 - src/compile/mod.rs | 2 -- src/compile/project.rs | 5 +---- src/error.rs | 26 ++++++++++++-------------- src/filter.rs | 10 +++------- src/lib.rs | 4 +++- src/project_util/mock.rs | 1 - src/project_util/mod.rs | 2 +- src/report/mod.rs | 6 +++--- src/resolver/mod.rs | 4 +--- src/resolver/parse.rs | 3 +-- src/resolver/tree.rs | 2 +- src/sourcemap.rs | 5 ----- tests/project.rs | 7 ------- 14 files changed, 26 insertions(+), 52 deletions(-) diff --git a/src/artifact_output/mod.rs b/src/artifact_output/mod.rs index 7290d76b..03d12d10 100644 --- a/src/artifact_output/mod.rs +++ b/src/artifact_output/mod.rs @@ -1118,7 +1118,6 @@ impl ArtifactOutput for MinimalCombinedArtifactsHardhatFallback { } #[cfg(test)] -#[allow(clippy::extra_unused_type_parameters)] mod tests { use super::*; diff --git a/src/compile/mod.rs b/src/compile/mod.rs index 8d8ee356..0e674040 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -64,7 +64,6 @@ pub static SUPPORTS_INCLUDE_PATH: Lazy = use std::sync::Mutex; #[cfg(any(test, feature = "tests"))] -#[allow(unused)] static LOCK: Lazy> = Lazy::new(|| Mutex::new(())); /// take the lock in tests, we use this to enforce that @@ -74,7 +73,6 @@ static LOCK: Lazy> = Lazy::new(|| Mutex::new(())); /// Instead of taking this lock in `Solc::blocking_install`, the lock should be taken before /// installation is detected. #[cfg(any(test, feature = "tests"))] -#[allow(unused)] pub(crate) fn take_solc_installer_lock() -> std::sync::MutexGuard<'static, ()> { LOCK.lock().unwrap() } diff --git a/src/compile/project.rs b/src/compile/project.rs index 7d87f5a6..fe84bcd3 100644 --- a/src/compile/project.rs +++ b/src/compile/project.rs @@ -378,11 +378,11 @@ impl<'a, T: ArtifactOutput> ArtifactsState<'a, T> { /// Determines how the `solc <-> sources` pairs are executed #[derive(Debug, Clone)] -#[allow(dead_code)] enum CompilerSources { /// Compile all these sequentially Sequential(VersionedSources), /// Compile all these in parallel using a certain amount of jobs + #[allow(dead_code)] Parallel(VersionedSources, usize), } @@ -452,7 +452,6 @@ impl CompilerSources { /// Determines how the `solc <-> sources` pairs are executed #[derive(Debug, Clone)] -#[allow(dead_code)] enum FilteredCompilerSources { /// Compile all these sequentially Sequential(VersionedFilteredSources), @@ -481,7 +480,6 @@ impl FilteredCompilerSources { } #[cfg(test)] - #[allow(unused)] fn sources(&self) -> &VersionedFilteredSources { match self { FilteredCompilerSources::Sequential(v) => v, @@ -682,7 +680,6 @@ mod tests { use std::path::PathBuf; - #[allow(unused)] fn init_tracing() { let _ = tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) diff --git a/src/error.rs b/src/error.rs index 5cd823c7..40c4acce 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,6 +7,18 @@ use thiserror::Error; pub type Result = std::result::Result; +#[allow(unused_macros)] +macro_rules! format_err { + ($($tt:tt)*) => { + $crate::error::SolcError::msg(format!($($tt)*)) + }; +} + +#[allow(unused_macros)] +macro_rules! bail { + ($($tt:tt)*) => { return Err(format_err!($($tt)*)) }; +} + /// Various error types #[derive(Debug, Error)] pub enum SolcError { @@ -86,20 +98,6 @@ impl SolcError { } } -macro_rules! _format_err { - ($($tt:tt)*) => { - $crate::error::SolcError::msg(format!($($tt)*)) - }; -} -#[allow(unused)] -pub(crate) use _format_err as format_err; - -macro_rules! _bail { - ($($tt:tt)*) => { return Err($crate::error::format_err!($($tt)*)) }; -} -#[allow(unused)] -pub(crate) use _bail as bail; - #[derive(Debug, Error)] #[error("\"{}\": {io}", self.path.display())] pub struct SolcIoError { diff --git a/src/filter.rs b/src/filter.rs index 4f1a6498..4122066f 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -18,10 +18,7 @@ pub trait FileFilter { fn is_match(&self, file: &Path) -> bool; } -impl FileFilter for F -where - F: Fn(&Path) -> bool, -{ +impl bool> FileFilter for F { fn is_match(&self, file: &Path) -> bool { (self)(file) } @@ -88,7 +85,7 @@ impl SparseOutputFilter { } } SparseOutputFilter::Custom(f) => { - Self::apply_custom_filter(&sources, settings, graph, f) + Self::apply_custom_filter(&sources, settings, graph, &**f) } }; sources.into() @@ -102,12 +99,11 @@ impl SparseOutputFilter { /// `*.t.sol` files and a test file makes use of a library that won't be inlined, then the /// libraries bytecode will be missing. Therefore, we detect all linkReferences of a file /// and treat them as if the filter would also apply to those. - #[allow(clippy::borrowed_box)] fn apply_custom_filter( sources: &FilteredSources, settings: &mut Settings, graph: &GraphEdges, - f: &Box, + f: &dyn FileFilter, ) { trace!("optimizing output selection with custom filter"); let selection = settings diff --git a/src/lib.rs b/src/lib.rs index e13ec888..233e0f97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,9 @@ #[macro_use] extern crate tracing; +#[macro_use] +pub mod error; + pub mod artifacts; pub mod sourcemap; @@ -33,7 +36,6 @@ pub use config::{AllowedLibPaths, PathStyle, ProjectPaths, ProjectPathsConfig, S pub mod remappings; use crate::artifacts::{Source, SourceFile, StandardJsonCompilerInput}; -pub mod error; mod filter; pub mod report; pub mod utils; diff --git a/src/project_util/mock.rs b/src/project_util/mock.rs index b876816e..af8e4034 100644 --- a/src/project_util/mock.rs +++ b/src/project_util/mock.rs @@ -362,7 +362,6 @@ impl MockProjectGenerator { } } -#[allow(clippy::derivable_impls)] impl Default for MockProjectGenerator { fn default() -> Self { Self { name_strategy: Box::::default(), inner: Default::default() } diff --git a/src/project_util/mod.rs b/src/project_util/mod.rs index 64bce0b4..c960eb53 100644 --- a/src/project_util/mod.rs +++ b/src/project_util/mod.rs @@ -3,7 +3,7 @@ use crate::{ artifacts::Settings, config::ProjectPathsConfigBuilder, - error::{bail, Result, SolcError}, + error::{Result, SolcError}, hh::HardhatArtifacts, project_util::mock::{MockProjectGenerator, MockProjectSettings}, remappings::Remapping, diff --git a/src/report/mod.rs b/src/report/mod.rs index f73cb644..a10bad15 100644 --- a/src/report/mod.rs +++ b/src/report/mod.rs @@ -199,17 +199,17 @@ pub(crate) fn solc_success( get_default(|r| r.reporter.on_solc_success(solc, version, output, duration)); } -#[allow(unused)] +#[allow(dead_code)] pub(crate) fn solc_installation_start(version: &Version) { get_default(|r| r.reporter.on_solc_installation_start(version)); } -#[allow(unused)] +#[allow(dead_code)] pub(crate) fn solc_installation_success(version: &Version) { get_default(|r| r.reporter.on_solc_installation_success(version)); } -#[allow(unused)] +#[allow(dead_code)] pub(crate) fn solc_installation_error(version: &Version, error: &str) { get_default(|r| r.reporter.on_solc_installation_error(version, error)); } diff --git a/src/resolver/mod.rs b/src/resolver/mod.rs index 223d316c..9bbec7ba 100644 --- a/src/resolver/mod.rs +++ b/src/resolver/mod.rs @@ -93,7 +93,6 @@ pub struct GraphEdges { /// Absolute imports, like `import "src/Contract.sol"` are possible, but this does not play /// nice with the standard-json import format, since the VFS won't be able to resolve /// "src/Contract.sol" without help via `--include-path` - #[allow(unused)] resolved_solc_include_paths: IncludePaths, } @@ -204,7 +203,6 @@ pub struct Graph { /// relationship of the nodes edges: GraphEdges, /// the root of the project this graph represents - #[allow(unused)] root: PathBuf, } @@ -936,7 +934,7 @@ impl<'a> fmt::Display for DisplayNode<'a> { /// Errors thrown when checking the solc version of a file #[derive(Debug, thiserror::Error)] -#[allow(unused)] +#[allow(dead_code)] enum SourceVersionError { #[error("Failed to parse solidity version {0}: {1}")] InvalidVersion(String, SolcError), diff --git a/src/resolver/parse.rs b/src/resolver/parse.rs index e05a5210..b99db5eb 100644 --- a/src/resolver/parse.rs +++ b/src/resolver/parse.rs @@ -11,7 +11,6 @@ use std::{ /// Represents various information about a solidity file parsed via [solang_parser] #[derive(Debug)] -#[allow(unused)] pub struct SolData { pub license: Option>, pub version: Option>, @@ -23,7 +22,7 @@ pub struct SolData { } impl SolData { - #[allow(unused)] + #[allow(dead_code)] pub fn fmt_version( &self, f: &mut W, diff --git a/src/resolver/tree.rs b/src/resolver/tree.rs index e140c3ab..a6181e11 100644 --- a/src/resolver/tree.rs +++ b/src/resolver/tree.rs @@ -132,7 +132,7 @@ fn print_node( } /// Prints all the imports of a node -#[allow(clippy::too_many_arguments, clippy::ptr_arg)] +#[allow(clippy::too_many_arguments)] fn print_imports( graph: &Graph, node_index: usize, diff --git a/src/sourcemap.rs b/src/sourcemap.rs index 1be14c13..f189245d 100644 --- a/src/sourcemap.rs +++ b/src/sourcemap.rs @@ -501,11 +501,6 @@ pub fn parse(input: &str) -> Result { mod tests { use super::*; - #[allow(unused)] - fn tokenize(s: &str) -> Vec> { - TokenStream::new(s).collect() - } - #[test] fn can_parse_source_maps() { // all source maps from the compiler output test data diff --git a/tests/project.rs b/tests/project.rs index 84950940..5311ba8c 100644 --- a/tests/project.rs +++ b/tests/project.rs @@ -24,13 +24,6 @@ use std::{ str::FromStr, }; -#[allow(unused)] -fn init_tracing() { - tracing_subscriber::fmt() - .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .init(); -} - #[test] fn can_get_versioned_linkrefs() { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/test-versioned-linkrefs");