Skip to content

Commit af513b9

Browse files
committed
clippy
1 parent 1975161 commit af513b9

File tree

11 files changed

+24
-59
lines changed

11 files changed

+24
-59
lines changed

worker-build/src/wasm_pack/bindgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::wasm_pack::command::build::{BuildProfile, Target};
55
use crate::wasm_pack::install::{self, Tool};
66
use crate::wasm_pack::manifest::CrateData;
77
use anyhow::{bail, Context, Result};
8-
use semver;
98
use std::path::Path;
109
use std::process::Command;
1110

1211
/// Run the `wasm-bindgen` CLI to generate bindings for the current crate's
1312
/// `.wasm`.
13+
#[allow(clippy::too_many_arguments)]
1414
pub fn wasm_bindgen_build(
1515
data: &CrateData,
1616
install_status: &install::Status,
@@ -21,7 +21,7 @@ pub fn wasm_bindgen_build(
2121
reference_types: bool,
2222
target: Target,
2323
profile: BuildProfile,
24-
extra_options: &Vec<String>,
24+
extra_options: &[String],
2525
) -> Result<()> {
2626
let profile_name = match profile.clone() {
2727
BuildProfile::Release | BuildProfile::Profiling => "release",

worker-build/src/wasm_pack/build/wasm_target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn check_for_wasm32_target() -> Result<()> {
6868
/// Get rustc's sysroot as a PathBuf
6969
fn get_rustc_sysroot() -> Result<PathBuf> {
7070
let command = Command::new("rustc")
71-
.args(&["--print", "sysroot"])
71+
.args(["--print", "sysroot"])
7272
.output()?;
7373

7474
if command.status.success() {
@@ -84,7 +84,7 @@ fn get_rustc_sysroot() -> Result<PathBuf> {
8484
/// Get wasm32-unknown-unknown target libdir
8585
fn get_rustc_wasm32_unknown_unknown_target_libdir() -> Result<PathBuf> {
8686
let command = Command::new("rustc")
87-
.args(&[
87+
.args([
8888
"--target",
8989
"wasm32-unknown-unknown",
9090
"--print",

worker-build/src/wasm_pack/command/build.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ pub struct Build {
4545

4646
/// What sort of output we're going to be generating and flags we're invoking
4747
/// `wasm-bindgen` with.
48-
#[derive(Clone, Copy, Debug)]
48+
#[derive(Clone, Copy, Debug, Default)]
4949
pub enum Target {
5050
/// Default output mode or `--target bundler`, indicates output will be
5151
/// used with a bundle in a later step.
52+
#[default]
5253
Bundler,
5354
/// Correspond to `--target web` where the output is natively usable as an
5455
/// ES module in a browser and the wasm is manually instantiated.
@@ -65,12 +66,6 @@ pub enum Target {
6566
Deno,
6667
}
6768

68-
impl Default for Target {
69-
fn default() -> Target {
70-
Target::Bundler
71-
}
72-
}
73-
7469
impl fmt::Display for Target {
7570
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7671
let s = match self {
@@ -113,7 +108,7 @@ pub enum BuildProfile {
113108
}
114109

115110
/// Everything required to configure and run the `wasm-pack build` command.
116-
#[derive(Debug, Args)]
111+
#[derive(Debug, Args, Default)]
117112
#[command(allow_hyphen_values = true, trailing_var_arg = true)]
118113
pub struct BuildOptions {
119114
/// The path to the Rust crate. If not set, searches up the path from the current directory.
@@ -186,30 +181,6 @@ pub struct BuildOptions {
186181
pub extra_options: Vec<String>,
187182
}
188183

189-
impl Default for BuildOptions {
190-
fn default() -> Self {
191-
Self {
192-
path: None,
193-
scope: None,
194-
mode: InstallMode::default(),
195-
disable_dts: false,
196-
weak_refs: false,
197-
reference_types: false,
198-
target: Target::default(),
199-
debug: false,
200-
dev: false,
201-
no_pack: false,
202-
no_opt: false,
203-
release: false,
204-
profiling: false,
205-
profile: None,
206-
out_dir: String::new(),
207-
out_name: None,
208-
extra_options: Vec::new(),
209-
}
210-
}
211-
}
212-
213184
type BuildStep = fn(&mut Build) -> Result<()>;
214185

215186
impl Build {
@@ -290,6 +261,7 @@ impl Build {
290261
Ok(())
291262
}
292263

264+
#[allow(clippy::vec_init_then_push)]
293265
fn get_process_steps(
294266
mode: InstallMode,
295267
no_pack: bool,

worker-build/src/wasm_pack/install/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn get_cli_version(tool: &Tool, path: &Path) -> Result<String> {
104104
let mut cmd = Command::new(path);
105105
cmd.arg("--version");
106106
let stdout = child::run_capture_stdout(cmd, tool)?;
107-
let version = stdout.trim().split_whitespace().nth(1);
107+
let version = stdout.split_whitespace().nth(1);
108108
match version {
109109
Some(v) => Ok(v.to_string()),
110110
None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.")

worker-build/src/wasm_pack/install/mode.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::str::FromStr;
33

44
/// The `InstallMode` determines which mode of initialization we are running, and
55
/// what install steps we perform.
6-
#[derive(Clone, Copy, Debug)]
6+
#[derive(Clone, Copy, Debug, Default)]
77
pub enum InstallMode {
88
/// Perform all the install steps.
9+
#[default]
910
Normal,
1011
/// Don't install tools like `wasm-bindgen`, just use the global
1112
/// environment's existing versions to do builds.
@@ -14,12 +15,6 @@ pub enum InstallMode {
1415
Force,
1516
}
1617

17-
impl Default for InstallMode {
18-
fn default() -> InstallMode {
19-
InstallMode::Normal
20-
}
21-
}
22-
2318
impl FromStr for InstallMode {
2419
type Err = Error;
2520
fn from_str(s: &str) -> Result<Self> {

worker-build/src/wasm_pack/license.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ fn glob_license_files(path: &Path) -> Result<Vec<String>> {
3939
/// Copy the crate's license into the `pkg` directory.
4040
pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> Result<()> {
4141
assert!(
42-
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
42+
fs::metadata(path).ok().is_some_and(|m| m.is_dir()),
4343
"crate directory should exist"
4444
);
4545

4646
assert!(
47-
fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()),
47+
fs::metadata(out_dir).ok().is_some_and(|m| m.is_dir()),
4848
"crate's pkg directory should exist"
4949
);
5050

worker-build/src/wasm_pack/lockfile.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::wasm_pack::manifest::CrateData;
99
use anyhow::{anyhow, bail, Context, Result};
1010
use console::style;
1111
use serde::Deserialize;
12-
use toml;
1312

1413
/// This struct represents the contents of `Cargo.lock`.
1514
#[derive(Clone, Debug, Deserialize)]

worker-build/src/wasm_pack/manifest/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ use crate::wasm_pack::command::build::{BuildProfile, Target};
1919
use crate::wasm_pack::PBAR;
2020
use cargo_metadata::{CrateType, Metadata, TargetKind};
2121
use serde::{self, Deserialize};
22-
use serde_json;
2322
use std::collections::BTreeSet;
2423
use strsim::levenshtein;
25-
use toml;
2624

2725
const WASM_PACK_METADATA_KEY: &str = "package.metadata.wasm-pack";
2826

@@ -334,8 +332,8 @@ impl CrateData {
334332
}
335333

336334
fn is_same_path(path1: &Path, path2: &Path) -> bool {
337-
if let Ok(path1) = fs::canonicalize(&path1) {
338-
if let Ok(path2) = fs::canonicalize(&path2) {
335+
if let Ok(path1) = fs::canonicalize(path1) {
336+
if let Ok(path2) = fs::canonicalize(path2) {
339337
return path1 == path2;
340338
}
341339
}
@@ -350,7 +348,7 @@ impl CrateData {
350348
/// Will return Err if the file (manifest_path) couldn't be read or
351349
/// if deserialize to `CargoManifest` fails.
352350
pub fn parse_crate_data(manifest_path: &Path) -> Result<ManifestAndUnsedKeys> {
353-
let manifest = fs::read_to_string(&manifest_path)
351+
let manifest = fs::read_to_string(manifest_path)
354352
.with_context(|| anyhow!("failed to read: {}", manifest_path.display()))?;
355353
let manifest = toml::Deserializer::parse(&manifest)?;
356354

@@ -407,8 +405,8 @@ impl CrateData {
407405
let any_cdylib = pkg
408406
.targets
409407
.iter()
410-
.filter(|target| target.kind.iter().any(|k| *k == TargetKind::CDyLib))
411-
.any(|target| target.crate_types.iter().any(|s| *s == CrateType::CDyLib));
408+
.filter(|target| target.kind.contains(&TargetKind::CDyLib))
409+
.any(|target| target.crate_types.contains(&CrateType::CDyLib));
412410
if any_cdylib {
413411
return Ok(());
414412
}
@@ -430,7 +428,7 @@ impl CrateData {
430428
match pkg
431429
.targets
432430
.iter()
433-
.find(|t| t.kind.iter().any(|k| *k == TargetKind::CDyLib))
431+
.find(|t| t.kind.contains(&TargetKind::CDyLib))
434432
{
435433
Some(lib) => lib.name.replace("-", "_"),
436434
None => pkg.name.replace("-", "_"),
@@ -544,7 +542,7 @@ impl CrateData {
544542
None
545543
};
546544

547-
let keywords = if pkg.keywords.len() > 0 {
545+
let keywords = if !pkg.keywords.is_empty() {
548546
Some(pkg.keywords.clone())
549547
} else {
550548
None

worker-build/src/wasm_pack/manifest/npm/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub use self::nomodules::NoModulesPackage;
1111

1212
#[derive(Serialize)]
1313
#[serde(untagged)]
14+
#[allow(clippy::enum_variant_names)]
1415
pub enum NpmPackage {
1516
CommonJSPackage(CommonJSPackage),
1617
ESModulesPackage(ESModulesPackage),

worker-build/src/wasm_pack/readme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use crate::wasm_pack::PBAR;
1010
/// Copy the crate's README into the `pkg` directory.
1111
pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> Result<()> {
1212
assert!(
13-
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
13+
fs::metadata(path).ok().is_some_and(|m| m.is_dir()),
1414
"crate directory should exist"
1515
);
1616
assert!(
17-
fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()),
17+
fs::metadata(out_dir).ok().is_some_and(|m| m.is_dir()),
1818
"crate's pkg directory should exist"
1919
);
2020

0 commit comments

Comments
 (0)