Skip to content

Commit

Permalink
Fix nightly clippy warnings (use-ink#167)
Browse files Browse the repository at this point in the history
* Fix `#[warn(clippy::ptr_arg)]`

* Fix `#[warn(clippy::ptr_arg)]`

* Fix `#[warn(clippy::match_like_matches_macro)]`

* Fix `#[warn(clippy::type_complexity)]`
  • Loading branch information
Michael Müller authored Feb 3, 2021
1 parent dfcca38 commit 3954049
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
)
});
}

Expand Down
23 changes: 18 additions & 5 deletions src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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<Url>,
homepage: Option<Url>,
user: Option<Map<String, Value>>,
}

/// Read extra metadata not available via `cargo metadata` directly from `Cargo.toml`
fn get_cargo_toml_metadata(
manifest_path: &ManifestPath,
) -> Result<(Option<Url>, Option<Url>, Option<Map<String, Value>>)> {
fn get_cargo_toml_metadata(manifest_path: &ManifestPath) -> Result<ExtraMetadata> {
let toml = fs::read_to_string(manifest_path)?;
let toml: value::Table = toml::from_str(&toml)?;

Expand Down Expand Up @@ -151,5 +160,9 @@ fn get_cargo_toml_metadata(
})
.transpose()?;

Ok((documentation, homepage, user))
Ok(ExtraMetadata {
documentation,
homepage,
user,
})
}
3 changes: 1 addition & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3954049

Please sign in to comment.