From 69c5624b17c8df3f0de0a02d2b50c890c20bbf16 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 4 Sep 2021 20:51:59 -0700 Subject: [PATCH] fix: remove needless clones, borrows --- src/bindgen.rs | 18 +++++++++--------- src/build/wasm_target.rs | 4 ++-- src/command/build.rs | 6 +++--- src/install/mod.rs | 10 +++++----- src/manifest/mod.rs | 2 +- src/test/webdriver.rs | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 02d02dc..535d6b8 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -6,7 +6,7 @@ use failure::{self, ResultExt}; use install::{self, Tool}; use manifest::CrateData; use semver; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process::Command; /// Run the `wasm-bindgen` CLI to generate bindings for the current crate's @@ -49,7 +49,7 @@ pub fn wasm_bindgen_build( .arg(dts_arg); let target_arg = build_target_arg(target, &bindgen_path)?; - if supports_dash_dash_target(bindgen_path.to_path_buf())? { + if supports_dash_dash_target(&bindgen_path)? { cmd.arg("--target").arg(target_arg); } else { cmd.arg(target_arg); @@ -75,7 +75,7 @@ pub fn wasm_bindgen_build( } /// Check if the `wasm-bindgen` dependency is locally satisfied for the web target -fn supports_web_target(cli_path: &PathBuf) -> Result { +fn supports_web_target(cli_path: &Path) -> Result { let cli_version = semver::Version::parse(&install::get_cli_version( &install::Tool::WasmBindgen, cli_path, @@ -85,30 +85,30 @@ fn supports_web_target(cli_path: &PathBuf) -> Result { } /// Check if the `wasm-bindgen` dependency is locally satisfied for the --target flag -fn supports_dash_dash_target(cli_path: PathBuf) -> Result { +fn supports_dash_dash_target(cli_path: &Path) -> Result { let cli_version = semver::Version::parse(&install::get_cli_version( &install::Tool::WasmBindgen, - &cli_path, + cli_path, )?)?; let expected_version = semver::Version::parse("0.2.40")?; Ok(cli_version >= expected_version) } -fn build_target_arg(target: Target, cli_path: &PathBuf) -> Result { - if !supports_dash_dash_target(cli_path.to_path_buf())? { +fn build_target_arg(target: Target, cli_path: &Path) -> Result { + if !supports_dash_dash_target(cli_path)? { Ok(build_target_arg_legacy(target, cli_path)?) } else { Ok(target.to_string()) } } -fn build_target_arg_legacy(target: Target, cli_path: &PathBuf) -> Result { +fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result { log::info!("Your version of wasm-bindgen is out of date. You should consider updating your Cargo.toml to a version >= 0.2.40."); let target_arg = match target { Target::Nodejs => "--nodejs", Target::NoModules => "--no-modules", Target::Web => { - if supports_web_target(&cli_path)? { + if supports_web_target(cli_path)? { "--web" } else { bail!("Your current version of wasm-bindgen does not support the 'web' target. Please update your project to wasm-bindgen version >= 0.2.39.") diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 27fb2ca..f3cdf11 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -5,7 +5,7 @@ use emoji; use failure::{Error, ResultExt}; use log::info; use std::fmt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use PBAR; @@ -81,7 +81,7 @@ fn get_rustc_sysroot() -> Result { } /// Checks if the wasm32-unknown-unknown is present in rustc's sysroot. -fn is_wasm32_target_in_sysroot(sysroot: &PathBuf) -> bool { +fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { let wasm32_target = "wasm32-unknown-unknown"; let rustlib_path = sysroot.join("lib/rustlib"); diff --git a/src/command/build.rs b/src/command/build.rs index e18a77c..b680270 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -190,7 +190,7 @@ impl Build { let path = build_opts.path.take().unwrap(); build_opts .extra_options - .insert(0, path.to_string_lossy().into_owned().to_string()); + .insert(0, path.to_string_lossy().into_owned()); } } let crate_path = get_crate_path(build_opts.path)?; @@ -370,7 +370,7 @@ impl Build { let bindgen = install::download_prebuilt_or_cargo_install( Tool::WasmBindgen, &self.cache, - &bindgen_version, + bindgen_version, self.mode.install_permitted(), )?; self.bindgen = Some(bindgen); @@ -382,7 +382,7 @@ impl Build { info!("Building the wasm bindings..."); bindgen::wasm_bindgen_build( &self.crate_data, - &self.bindgen.as_ref().unwrap(), + self.bindgen.as_ref().unwrap(), &self.out_dir, &self.out_name, self.disable_dts, diff --git a/src/install/mod.rs b/src/install/mod.rs index 071c821..06bf72a 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -10,7 +10,7 @@ use log::debug; use log::{info, warn}; use std::env; use std::fs; -use std::path::PathBuf; +use std::path::Path; use std::process::Command; use target; use which::which; @@ -71,7 +71,7 @@ pub fn download_prebuilt_or_cargo_install( let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool); PBAR.info(&msg); - let dl = download_prebuilt(&tool, &cache, version, install_permitted); + let dl = download_prebuilt(&tool, cache, version, install_permitted); match dl { Ok(dl) => return Ok(dl), Err(e) => { @@ -82,13 +82,13 @@ pub fn download_prebuilt_or_cargo_install( } } - cargo_install(tool, &cache, version, install_permitted) + cargo_install(tool, cache, version, install_permitted) } /// Check if the tool dependency is locally satisfied. pub fn check_version( tool: &Tool, - path: &PathBuf, + path: &Path, expected_version: &str, ) -> Result { let expected_version = if expected_version == "latest" { @@ -107,7 +107,7 @@ pub fn check_version( } /// Fetches the version of a CLI tool -pub fn get_cli_version(tool: &Tool, path: &PathBuf) -> Result { +pub fn get_cli_version(tool: &Tool, path: &Path) -> Result { let mut cmd = Command::new(path); cmd.arg("--version"); let stdout = child::run_capture_stdout(cmd, tool)?; diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index e82451c..898de42 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -644,7 +644,7 @@ impl CrateData { files, main: js_file, homepage: self.manifest.package.homepage.clone(), - keywords: keywords, + keywords, } } diff --git a/src/test/webdriver.rs b/src/test/webdriver.rs index f0f34e8..93de546 100644 --- a/src/test/webdriver.rs +++ b/src/test/webdriver.rs @@ -23,13 +23,13 @@ fn get_and_notify( name: &str, url: &str, ) -> Result, failure::Error> { - if let Some(dl) = cache.download(false, name, &[name], &url)? { + if let Some(dl) = cache.download(false, name, &[name], url)? { return Ok(Some(dl.binary(name)?)); } if installation_allowed { PBAR.info(&format!("Getting {}...", name)); } - match cache.download(installation_allowed, name, &[name], &url)? { + match cache.download(installation_allowed, name, &[name], url)? { Some(dl) => Ok(Some(dl.binary(name)?)), None => Ok(None), }