chore(clippy): make clippy happy (#1856)

This commit is contained in:
Matthias Seitz 2022-11-13 13:49:27 +01:00 committed by GitHub
parent 3b52c2fc7e
commit cba6f071ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 29 deletions

View File

@ -493,8 +493,8 @@ mod tests {
assert_eq!(parse_units("3_3_0", 3).unwrap(), U256::from(330000), "underscore"); assert_eq!(parse_units("3_3_0", 3).unwrap(), U256::from(330000), "underscore");
assert_eq!(parse_units("330", 0).unwrap(), U256::from(330), "zero decimals"); assert_eq!(parse_units("330", 0).unwrap(), U256::from(330), "zero decimals");
assert_eq!(parse_units(".1234", 3).unwrap(), U256::from(123), "truncate too many decimals"); assert_eq!(parse_units(".1234", 3).unwrap(), U256::from(123), "truncate too many decimals");
assert_eq!(parse_units("1", 80).is_err(), true, "overflow"); assert!(parse_units("1", 80).is_err(), "overflow");
assert_eq!(parse_units("1", -1).is_err(), true, "neg units"); assert!(parse_units("1", -1).is_err(), "neg units");
let two_e30 = U256::from(2) * U256([0x4674edea40000000, 0xc9f2c9cd0, 0x0, 0x0]); let two_e30 = U256::from(2) * U256([0x4674edea40000000, 0xc9f2c9cd0, 0x0, 0x0]);
assert_eq!(parse_units("2", 30).unwrap(), two_e30, "2e30"); assert_eq!(parse_units("2", 30).unwrap(), two_e30, "2e30");
assert_eq!(parse_units(".33_319_2", 0).unwrap(), U256::zero(), "mix"); assert_eq!(parse_units(".33_319_2", 0).unwrap(), U256::zero(), "mix");

View File

@ -400,7 +400,9 @@ impl<T: ArtifactOutput> fmt::Display for ProjectCompileOutput<T> {
if self.compiler_output.is_unchanged() { if self.compiler_output.is_unchanged() {
f.write_str("Nothing to compile") f.write_str("Nothing to compile")
} else { } else {
self.compiler_output.diagnostics(&self.ignored_error_codes, self.compiler_severity_filter.clone()).fmt(f) self.compiler_output
.diagnostics(&self.ignored_error_codes, self.compiler_severity_filter.clone())
.fmt(f)
} }
} }
} }
@ -428,7 +430,11 @@ impl AggregatedCompilerOutput {
} }
/// Whether the output contains a compiler error /// Whether the output contains a compiler error
pub fn has_error(&self, ignored_error_codes: &[u64], compiler_severity_filter: &Severity) -> bool { pub fn has_error(
&self,
ignored_error_codes: &[u64],
compiler_severity_filter: &Severity,
) -> bool {
self.errors.iter().any(|err| { self.errors.iter().any(|err| {
if compiler_severity_filter.ge(&err.severity) { if compiler_severity_filter.ge(&err.severity) {
if compiler_severity_filter.is_warning() { if compiler_severity_filter.is_warning() {
@ -436,7 +442,7 @@ impl AggregatedCompilerOutput {
} }
return true return true
} }
return false false
}) })
} }
@ -451,7 +457,11 @@ impl AggregatedCompilerOutput {
}) })
} }
pub fn diagnostics<'a>(&'a self, ignored_error_codes: &'a [u64], compiler_severity_filter: Severity) -> OutputDiagnostics { pub fn diagnostics<'a>(
&'a self,
ignored_error_codes: &'a [u64],
compiler_severity_filter: Severity,
) -> OutputDiagnostics {
OutputDiagnostics { compiler_output: self, ignored_error_codes, compiler_severity_filter } OutputDiagnostics { compiler_output: self, ignored_error_codes, compiler_severity_filter }
} }
@ -719,7 +729,7 @@ pub struct OutputDiagnostics<'a> {
impl<'a> OutputDiagnostics<'a> { impl<'a> OutputDiagnostics<'a> {
/// Returns true if there is at least one error of high severity /// Returns true if there is at least one error of high severity
pub fn has_error(&self) -> bool { pub fn has_error(&self) -> bool {
self.compiler_output.has_error(&self.ignored_error_codes, &self.compiler_severity_filter) self.compiler_output.has_error(self.ignored_error_codes, &self.compiler_severity_filter)
} }
/// Returns true if there is at least one warning /// Returns true if there is at least one warning

View File

@ -311,7 +311,8 @@ impl<'a, T: ArtifactOutput> CompiledState<'a, T> {
ctx, ctx,
&project.paths, &project.paths,
) )
} else if output.has_error(&project.ignored_error_codes, &project.compiler_severity_filter) { } else if output.has_error(&project.ignored_error_codes, &project.compiler_severity_filter)
{
trace!("skip writing cache file due to solc errors: {:?}", output.errors); trace!("skip writing cache file due to solc errors: {:?}", output.errors);
project.artifacts_handler().output_to_artifacts( project.artifacts_handler().output_to_artifacts(
&output.contracts, &output.contracts,
@ -361,14 +362,15 @@ impl<'a, T: ArtifactOutput> ArtifactsState<'a, T> {
let project = cache.project(); let project = cache.project();
let ignored_error_codes = project.ignored_error_codes.clone(); let ignored_error_codes = project.ignored_error_codes.clone();
let compiler_severity_filter = project.compiler_severity_filter.clone(); let compiler_severity_filter = project.compiler_severity_filter.clone();
let skip_write_to_disk = project.no_artifacts || output.has_error(&ignored_error_codes, &compiler_severity_filter); let skip_write_to_disk = project.no_artifacts ||
output.has_error(&ignored_error_codes, &compiler_severity_filter);
let cached_artifacts = cache.consume(&compiled_artifacts, !skip_write_to_disk)?; let cached_artifacts = cache.consume(&compiled_artifacts, !skip_write_to_disk)?;
Ok(ProjectCompileOutput { Ok(ProjectCompileOutput {
compiler_output: output, compiler_output: output,
compiled_artifacts, compiled_artifacts,
cached_artifacts, cached_artifacts,
ignored_error_codes, ignored_error_codes,
compiler_severity_filter compiler_severity_filter,
}) })
} }
} }

View File

@ -1623,8 +1623,8 @@ fn test_compiler_severity_filter() {
fn gen_test_data_warning_path() -> ProjectPathsConfig { fn gen_test_data_warning_path() -> ProjectPathsConfig {
let root = let root =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/test-contract-warnings"); PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/test-contract-warnings");
let paths = ProjectPathsConfig::builder().sources(root).build().unwrap();
paths ProjectPathsConfig::builder().sources(root).build().unwrap()
} }
let project = Project::builder() let project = Project::builder()
@ -1652,10 +1652,10 @@ fn test_compiler_severity_filter() {
#[test] #[test]
fn test_compiler_severity_filter_and_ignored_error_codes() { fn test_compiler_severity_filter_and_ignored_error_codes() {
fn gen_test_data_licensing_warning() -> ProjectPathsConfig { fn gen_test_data_licensing_warning() -> ProjectPathsConfig {
let root = let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/test-contract-warnings/LicenseWarning.sol"); .join("test-data/test-contract-warnings/LicenseWarning.sol");
let paths = ProjectPathsConfig::builder().sources(root).build().unwrap();
paths ProjectPathsConfig::builder().sources(root).build().unwrap()
} }
let missing_license_error_code = 1878; let missing_license_error_code = 1878;