From 3954049f6f25ae427dd9572a3fa2efb1424a031b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 3 Feb 2021 12:00:54 +0100 Subject: [PATCH] Fix nightly clippy warnings (#167) * Fix `#[warn(clippy::ptr_arg)]` * Fix `#[warn(clippy::ptr_arg)]` * Fix `#[warn(clippy::match_like_matches_macro)]` * Fix `#[warn(clippy::type_complexity)]` --- src/cmd/build.rs | 10 +++++----- src/crate_metadata.rs | 23 ++++++++++++++++++----- src/util.rs | 3 +-- src/workspace/manifest.rs | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 6708e6014..adf88e90b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -222,11 +222,11 @@ fn ensure_maximum_memory_pages(module: &mut Module, maximum_allowed_pages: u32) /// /// Presently all custom sections are not required so they can be stripped safely. fn strip_custom_sections(module: &mut Module) { - module.sections_mut().retain(|section| match section { - Section::Custom(_) => false, - Section::Name(_) => false, - Section::Reloc(_) => false, - _ => true, + module.sections_mut().retain(|section| { + !matches!( + section, + Section::Custom(_) | Section::Name(_) | Section::Reloc(_) + ) }); } diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index ce659efae..5633f0be2 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -75,7 +75,11 @@ impl CrateMetadata { }) .ok_or_else(|| anyhow::anyhow!("No 'ink_lang' dependency found"))?; - let (documentation, homepage, user) = get_cargo_toml_metadata(manifest_path)?; + let ExtraMetadata { + documentation, + homepage, + user, + } = get_cargo_toml_metadata(manifest_path)?; let crate_metadata = CrateMetadata { manifest_path: manifest_path.clone(), @@ -118,10 +122,15 @@ fn get_cargo_metadata(manifest_path: &ManifestPath) -> Result<(CargoMetadata, Pa Ok((metadata, root_package)) } +/// Extra metadata not available via `cargo metadata`. +struct ExtraMetadata { + documentation: Option, + homepage: Option, + user: Option>, +} + /// Read extra metadata not available via `cargo metadata` directly from `Cargo.toml` -fn get_cargo_toml_metadata( - manifest_path: &ManifestPath, -) -> Result<(Option, Option, Option>)> { +fn get_cargo_toml_metadata(manifest_path: &ManifestPath) -> Result { let toml = fs::read_to_string(manifest_path)?; let toml: value::Table = toml::from_str(&toml)?; @@ -151,5 +160,9 @@ fn get_cargo_toml_metadata( }) .transpose()?; - Ok((documentation, homepage, user)) + Ok(ExtraMetadata { + documentation, + homepage, + user, + }) } diff --git a/src/util.rs b/src/util.rs index 04edfde4a..ece7a0c0b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,7 +17,6 @@ use crate::Verbosity; use anyhow::{Context, Result}; use rustc_version::Channel; -use std::path::PathBuf; use std::{ffi::OsStr, path::Path, process::Command}; /// Check whether the current rust channel is valid: `nightly` is recommended. @@ -86,7 +85,7 @@ where } /// Returns the base name of the path. -pub(crate) fn base_name(path: &PathBuf) -> &str { +pub(crate) fn base_name(path: &Path) -> &str { path.file_name() .expect("file name must exist") .to_str() diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 70ac93663..40ef117c5 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -399,7 +399,7 @@ impl Manifest { } } -fn crate_type_exists(crate_type: &str, crate_types: &value::Array) -> bool { +fn crate_type_exists(crate_type: &str, crate_types: &[value::Value]) -> bool { crate_types .iter() .any(|v| v.as_str().map_or(false, |s| s == crate_type))