From 11022846845abd37a372084b8ab32188105bb026 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 21 Aug 2022 00:40:50 +1000 Subject: [PATCH] Fix `clippy` warnings and add new workflow clippy (#306) * Derive `Eq` for `PkgFmt`, `PkgFmtDecomposed` & `TarBasedFmt` * Derive `Eq` for `PkgMeta`, `PkgOverride` & `BinMeta` * Rm unnecessary reborrow in `install_from_source` * Rm unnecessary `into()` in `args::parse` * Fix `clippy` warning in `CratesToml::append_to_path` * Fix clippy warning in `cratesio_url` * Fix clippy warning in `detect_targets_linux` * Add `clippy` and `rustfmt` to workflow `unit-test` Because `clippy` would not check inactive code disabled by `cfg`, so we have to also run `clippy` on multiple targets. Signed-off-by: Jiahao XU --- .github/workflows/unit-tests.yml | 8 +++++++- crates/bin/src/args.rs | 2 +- crates/lib/src/helpers/statics.rs | 2 +- crates/lib/src/manifests/cargo_crates_v1.rs | 2 +- crates/lib/src/manifests/cargo_toml_binstall.rs | 6 +++--- .../src/manifests/cargo_toml_binstall/package_formats.rs | 6 +++--- crates/lib/src/ops/install.rs | 2 +- crates/lib/src/targets.rs | 5 ++--- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2ff389b8..57e10fff 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -27,7 +27,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure toolchain run: | - rustup toolchain install --profile minimal --no-self-update nightly + rustup toolchain install nightly --component rustfmt,clippy --no-self-update --profile minimal rustup default nightly - name: Configure caching @@ -53,3 +53,9 @@ jobs: - name: Test (Windows) if: matrix.os == 'windows' run: cargo test --no-default-features --features native-tls + + - name: fmt + run: cargo fmt --all --check + + - name: clippy + run: cargo clippy --no-deps -- -D clippy::all diff --git a/crates/bin/src/args.rs b/crates/bin/src/args.rs index bc8403e3..fcaec52f 100644 --- a/crates/bin/src/args.rs +++ b/crates/bin/src/args.rs @@ -244,7 +244,7 @@ pub fn parse() -> Result { }; if !option.is_empty() { - return Err(BinstallError::OverrideOptionUsedWithMultiInstall { option }.into()); + return Err(BinstallError::OverrideOptionUsedWithMultiInstall { option }); } } diff --git a/crates/lib/src/helpers/statics.rs b/crates/lib/src/helpers/statics.rs index ecc490c8..d2ff70ad 100644 --- a/crates/lib/src/helpers/statics.rs +++ b/crates/lib/src/helpers/statics.rs @@ -19,5 +19,5 @@ pub fn cratesio_url() -> &'static Url { static CRATESIO: Lazy Url> = Lazy::new(|| Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()); - &*CRATESIO + &CRATESIO } diff --git a/crates/lib/src/manifests/cargo_crates_v1.rs b/crates/lib/src/manifests/cargo_crates_v1.rs index a593ad0a..d197e8b4 100644 --- a/crates/lib/src/manifests/cargo_crates_v1.rs +++ b/crates/lib/src/manifests/cargo_crates_v1.rs @@ -99,7 +99,7 @@ impl CratesToml { } file.rewind()?; - c1.write_to_file(&mut *file)?; + c1.write_to_file(&mut file)?; Ok(()) } diff --git a/crates/lib/src/manifests/cargo_toml_binstall.rs b/crates/lib/src/manifests/cargo_toml_binstall.rs index 9f1ce933..72312ba2 100644 --- a/crates/lib/src/manifests/cargo_toml_binstall.rs +++ b/crates/lib/src/manifests/cargo_toml_binstall.rs @@ -30,7 +30,7 @@ pub struct Meta { /// Metadata for binary installation use. /// /// Exposed via `[package.metadata]` in `Cargo.toml` -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default)] pub struct PkgMeta { /// URL template for package downloads @@ -79,7 +79,7 @@ impl PkgMeta { /// Target specific overrides for binary installation /// /// Exposed via `[package.metadata.TARGET]` in `Cargo.toml` -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default)] pub struct PkgOverride { /// URL template override for package downloads @@ -92,7 +92,7 @@ pub struct PkgOverride { pub bin_dir: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct BinMeta { /// Binary name diff --git a/crates/lib/src/manifests/cargo_toml_binstall/package_formats.rs b/crates/lib/src/manifests/cargo_toml_binstall/package_formats.rs index 4368638e..f7caf2c4 100644 --- a/crates/lib/src/manifests/cargo_toml_binstall/package_formats.rs +++ b/crates/lib/src/manifests/cargo_toml_binstall/package_formats.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; /// Binary format enumeration -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, EnumString)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize, EnumString)] #[serde(rename_all = "snake_case")] pub enum PkgFmt { /// Download format is TAR (uncompressed) @@ -55,14 +55,14 @@ impl PkgFmt { } } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum PkgFmtDecomposed { Tar(TarBasedFmt), Bin, Zip, } -#[derive(Debug, Display, Copy, Clone, PartialEq)] +#[derive(Debug, Display, Copy, Clone, Eq, PartialEq)] pub enum TarBasedFmt { /// Download format is TAR (uncompressed) Tar, diff --git a/crates/lib/src/ops/install.rs b/crates/lib/src/ops/install.rs index b060b2f4..6632c50b 100644 --- a/crates/lib/src/ops/install.rs +++ b/crates/lib/src/ops/install.rs @@ -161,7 +161,7 @@ async fn install_from_source( .arg("--version") .arg(package.version) .arg("--target") - .arg(&*target); + .arg(target); if quiet { cmd.arg("--quiet"); diff --git a/crates/lib/src/targets.rs b/crates/lib/src/targets.rs index dc905383..57723bba 100644 --- a/crates/lib/src/targets.rs +++ b/crates/lib/src/targets.rs @@ -136,12 +136,11 @@ mod linux { pub(super) async fn detect_targets_linux() -> Vec { let (abi, libc) = parse_abi_and_libc(); - match libc { + if let Libc::Glibc = libc { // Glibc can only be dynamically linked. // If we can run this binary, then it means that the target // supports both glibc and musl. - Libc::Glibc => return create_targets_str(&["gnu", "musl"], abi), - _ => (), + return create_targets_str(&["gnu", "musl"], abi); } if let Ok(Output {