From 1a872f06bc99ec2075af5cbf09e30dbdf651889b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 25 Aug 2024 11:36:19 +0200 Subject: [PATCH 1/2] remove unnecessary clones, and some minor changes --- src/main.rs | 20 +++++++------------- src/search_unused.rs | 6 +++--- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index fb4bed9..57ce472 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,9 +79,10 @@ fn collect_paths(path: &Path, options: CollectPathOptions) -> Result entry.file_name() == "Cargo.toml", - Err(_) => true, + .filter(|entry| { + entry + .as_ref() + .map_or(true, |entry| entry.file_name() == "Cargo.toml") }) .map(|res_entry| res_entry.map(|e| e.into_path())) .collect() @@ -123,7 +124,6 @@ fn run_machete() -> anyhow::Result { "Analyzing dependencies of crates in {}...", args.paths .iter() - .cloned() .map(|path| path.as_os_str().to_string_lossy().to_string()) .collect::>() .join(",") @@ -191,17 +191,11 @@ fn run_machete() -> anyhow::Result { }; if results.is_empty() { - println!( - "cargo-machete didn't find any unused dependencies in {}. Good job!", - location - ); + println!("cargo-machete didn't find any unused dependencies in {location}. Good job!"); continue; } - println!( - "cargo-machete found the following unused dependencies in {}:", - location - ); + println!("cargo-machete found the following unused dependencies in {location}:"); for (analysis, path) in results { println!("{} -- {}:", analysis.package_name, path.to_string_lossy()); for dep in &analysis.unused { @@ -240,7 +234,7 @@ fn run_machete() -> anyhow::Result { ); } - println!() + println!(); } eprintln!("Done!"); diff --git a/src/search_unused.rs b/src/search_unused.rs index 9f2f93c..c88db1b 100644 --- a/src/search_unused.rs +++ b/src/search_unused.rs @@ -67,8 +67,8 @@ impl PackageAnalysis { metadata, manifest, package_name, - unused: Default::default(), - ignored_used: Default::default(), + unused: Vec::default(), + ignored_used: Vec::default(), }) } } @@ -333,7 +333,7 @@ pub(crate) fn find_unused( debug!("handling {} ({})", package_name, dir_path.display()); let mut analysis = PackageAnalysis::new( - package_name.clone(), + package_name, manifest_path, manifest, matches!(with_cargo_metadata, UseCargoMetadata::Yes), From 82d0e8a1f43a2e670e3159dcb7c62126be1cd112 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 25 Aug 2024 11:36:26 +0200 Subject: [PATCH 2/2] nump dependencies --- Cargo.lock | 71 ++++++++++++++++++------------------------------------ Cargo.toml | 8 +++--- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc75ae2..e773c58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "argh" @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.19.2" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" +checksum = "ad639525b1c67b6a298f378417b060fbc04618bea559482a8484381cce27d965" dependencies = [ "serde", "toml", @@ -305,17 +305,16 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "ignore" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" dependencies = [ + "crossbeam-deque", "globset", - "lazy_static", "log", "memchr", - "regex", + "regex-automata", "same-file", - "thread_local", "walkdir", "winapi-util", ] @@ -347,12 +346,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.153" @@ -361,9 +354,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" @@ -380,12 +373,6 @@ dependencies = [ "libc", ] -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "pretty_env_logger" version = "0.5.0" @@ -489,18 +476,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -520,9 +507,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -567,21 +554,11 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "toml" -version = "0.8.12" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", @@ -591,18 +568,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "serde", @@ -726,9 +703,9 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 9c3b9db..6266b45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,13 @@ license = "MIT" readme = "README.md" [dependencies] -anyhow = "1.0.57" +anyhow = "1.0.86" argh = "0.1.9" cargo_metadata = "0.18.0" -cargo_toml = "0.19.1" +cargo_toml = "0.20.4" grep = "0.3.1" -ignore = "0.4.20" -log = "0.4.16" +ignore = "0.4.22" +log = "0.4.22" pretty_env_logger = "0.5.0" rayon = "1.5.2" serde = "1.0.136"