From 9762cb20b8191fc7be3c38062008f61e1cc1477f Mon Sep 17 00:00:00 2001 From: vasilito Date: Sat, 18 Jul 2026 18:01:07 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20fix=20ptr=5Farg=20clippy=20warnings?= =?UTF-8?q?=20(&PathBuf=E2=86=92&Path,=20&Vec=E2=86=92&[T])?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduced warnings from 86 to 74 (12 warnings fixed across 16 function signatures). Changes: - &PathBuf → &Path (14 signatures in cook_build, fetch, fs) - &Vec → &[T] (2 signatures in cook_build, web/html) - &mut Vec → &mut [T] (1 signature in recipe) - Removed redundant to_path_buf() call exposed by signature change All callers unaffected via deref coercion. Verification: cargo check ✅, cargo test --lib ✅ 38/38, cargo clippy 74 remaining (70 result_large_err, 3 too_many_arguments, 1 if_same_then_else). --- src/cook/cook_build.rs | 6 +++--- src/cook/fetch.rs | 14 +++++++------- src/cook/fs.rs | 14 +++++++------- src/recipe.rs | 2 +- src/web.rs | 2 +- src/web/html.rs | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 047214d848..f959a5edd2 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -1069,7 +1069,7 @@ pub fn build( Ok(BuildResult::new(stage_dirs, auto_deps)) } -pub fn remove_stage_dir(stage_dir: &PathBuf) -> crate::Result<()> { +pub fn remove_stage_dir(stage_dir: &Path) -> crate::Result<()> { if stage_dir.is_dir() { remove_all(stage_dir)?; } @@ -1114,7 +1114,7 @@ pub fn get_sub_target_dir(target_dir: &Path, sub_path: &str) -> PathBuf { fn build_deps_dir( logger: &PtyOut, - deps_dir: &PathBuf, + deps_dir: &Path, dep_pkgars: &BTreeSet<(PackageName, PathBuf)>, source_modified: SystemTime, deps_modified: SystemTime, @@ -1205,7 +1205,7 @@ fn build_deps_dir( fn build_auto_deps( recipe: &Recipe, auto_deps_path: &Path, - stage_dirs: &Vec, + stage_dirs: &[PathBuf], cached: bool, cook_config: &CookConfig, mut dep_pkgars: BTreeSet<(PackageName, PathBuf)>, diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index ec12714bf7..0c0894a2f9 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -270,7 +270,7 @@ fn redbear_source_dir_is_effectively_empty(source_dir: &Path) -> bool { fn redbear_ensure_offline_source( recipe_dir: &Path, - source_dir: &PathBuf, + source_dir: &Path, logger: &PtyOut, ) -> Result<()> { if !source_dir.exists() || redbear_source_dir_is_effectively_empty(source_dir) { @@ -281,7 +281,7 @@ fn redbear_ensure_offline_source( fn redbear_ensure_offline_git_source( recipe_dir: &Path, - source_dir: &PathBuf, + source_dir: &Path, logger: &PtyOut, ) -> Result<()> { let git_head = source_dir.join(".git/HEAD"); @@ -1089,11 +1089,11 @@ pub(crate) fn fetch_extract_tar( } pub(crate) fn fetch_cargo( - source_dir: &PathBuf, + source_dir: &Path, cargopath: Option<&String>, logger: &PtyOut, ) -> Result<()> { - let mut source_dir = source_dir.clone(); + let mut source_dir = source_dir.to_path_buf(); if let Some(cargopath) = cargopath { source_dir = source_dir.join(cargopath); } @@ -1232,8 +1232,8 @@ fn read_source_toml(source_toml: &Path) -> Result { pub(crate) fn fetch_is_patches_newer( recipe_dir: &Path, - patches: &Vec, - source_dir: &PathBuf, + patches: &[String], + source_dir: &Path, ) -> Result { // don't check source files inside as it can be mixed with user patches let source_time = modified(source_dir)?; @@ -1639,7 +1639,7 @@ fn fetch_write_patches_state( script: &Option, logger: &PtyOut, ) -> Result<()> { - let head_rev = get_git_head_rev(&source_dir.to_path_buf()) + let head_rev = get_git_head_rev(source_dir) .map(|(r, _)| r) .unwrap_or_else(|_| "unknown".to_string()); let hash = fetch_compute_patches_hash(recipe_dir, applied) diff --git a/src/cook/fs.rs b/src/cook/fs.rs index 792616e47b..36c6d349c5 100644 --- a/src/cook/fs.rs +++ b/src/cook/fs.rs @@ -308,7 +308,7 @@ pub fn serialize_and_write(file_path: &Path, content: &T) -> Resul Ok(()) } -pub fn offline_check_exists(path: &PathBuf) -> Result<()> { +pub fn offline_check_exists(path: &Path) -> Result<()> { if !path.exists() { bail_other_err!( "{path:?} is not exist and unable to continue in offline mode", @@ -318,7 +318,7 @@ pub fn offline_check_exists(path: &PathBuf) -> Result<()> { Ok(()) } -pub fn download_wget(url: &str, dest: &PathBuf, logger: &PtyOut) -> Result<()> { +pub fn download_wget(url: &str, dest: &Path, logger: &PtyOut) -> Result<()> { if !dest.is_file() { let dest_tmp = PathBuf::from(format!("{}.tmp", dest.display())); let translated = translate_mirror(url); @@ -346,7 +346,7 @@ pub fn read_to_string(path: &Path) -> Result { } /// get commit rev and return if it's detached or not -pub fn get_git_head_rev(dir: &PathBuf) -> Result<(String, bool)> { +pub fn get_git_head_rev(dir: &Path) -> Result<(String, bool)> { let git_head = dir.join(".git/HEAD"); let head_str = read_to_string(&git_head)?; if let Some(stripped) = head_str.strip_prefix("ref: ") { @@ -364,14 +364,14 @@ pub fn get_git_head_rev(dir: &PathBuf) -> Result<(String, bool)> { } /// get commit from "rev" which either a full commit hash or a tag name -pub fn get_git_tag_rev(dir: &PathBuf, tag: &str) -> Result { +pub fn get_git_tag_rev(dir: &Path, tag: &str) -> Result { if tag.len() == 40 && tag.chars().all(|f| f.is_ascii_hexdigit()) { return Ok(tag.to_string()); } get_git_ref_entry(dir, &format!("refs/tags/{tag}")) } -pub fn get_git_ref_entry(dir: &PathBuf, entry: &str) -> Result { +pub fn get_git_ref_entry(dir: &Path, entry: &str) -> Result { // https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery let git_refs = dir.join(".git/packed-refs"); let refs_str = read_to_string(&git_refs)?; @@ -394,7 +394,7 @@ pub fn get_git_ref_entry(dir: &PathBuf, entry: &str) -> Result { } /// get commit rev after fetch -pub fn get_git_fetch_rev(dir: &PathBuf, remote_url: &str, remote_branch: &str) -> Result { +pub fn get_git_fetch_rev(dir: &Path, remote_url: &str, remote_branch: &str) -> Result { let git_fetch_head = dir.join(".git/FETCH_HEAD"); let fetch_head_content = read_to_string(&git_fetch_head)?; @@ -420,7 +420,7 @@ pub fn get_git_fetch_rev(dir: &PathBuf, remote_url: &str, remote_branch: &str) - /// (local_branch_name, remote_branch, remote_name, remote_url) /// -> ("fix_stuff", "master", "origin", "https://gitlab.redox-os.org/willnode/redox") -pub fn get_git_remote_tracking(dir: &PathBuf) -> Result<(String, String, String, String)> { +pub fn get_git_remote_tracking(dir: &Path) -> Result<(String, String, String, String)> { let git_head = dir.join(".git/HEAD"); let git_config = dir.join(".git/config"); diff --git a/src/recipe.rs b/src/recipe.rs index d4e366c435..9bc2cf371b 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -582,7 +582,7 @@ fn topological_sort(recipes: Vec) -> Result, Package // TODO: Wrap these vectors in a struct -pub fn recipes_mark_as_deps(names: &[PackageName], packages: &mut Vec) { +pub fn recipes_mark_as_deps(names: &[PackageName], packages: &mut [CookRecipe]) { for package in packages.iter_mut() { package.is_deps = !names.contains(&package.name); } diff --git a/src/web.rs b/src/web.rs index 94948db4a7..f71bbb0702 100644 --- a/src/web.rs +++ b/src/web.rs @@ -103,7 +103,7 @@ pub fn generate_web(all_packages: &Vec, config: &CliWebConfig) { generate_html_pkg( package, recipe, - &dependents.into_iter().collect(), + &dependents.into_iter().collect::>(), &stage_files, &html_path, config, diff --git a/src/web/html.rs b/src/web/html.rs index 0c33a710a9..0b02ff077f 100644 --- a/src/web/html.rs +++ b/src/web/html.rs @@ -9,7 +9,7 @@ use std::{fs, path::Path}; pub fn generate_html_pkg( package: &Package, recipe: &CookRecipe, - dependents: &Vec, + dependents: &[String], stage_files: &Option, html_path: &Path, config: &crate::web::CliWebConfig,