refactor: manual clippy fixes (manual_strip, borrowed_box, redundant_struct)
Reduced warnings from 96 to 86. Categories fixed (10 warnings): - manual_strip (5): starts_with + manual slice → strip_prefix/strip_suffix - borrowed_box (2): &Box<impl Fn> → &impl Fn (fs.rs signatures + caller) - redundant_struct_expression (2): remove ..Default::default() when all fields set - field_reassign_with_default (1): Default + field assign → struct literal Verification: cargo check ✅, cargo test --lib ✅ 38/38, cargo clippy 86 remaining.
This commit is contained in:
@@ -1001,14 +1001,14 @@ pub fn build(
|
||||
}
|
||||
move_dir_all_fn(
|
||||
&stage_dir_tmp,
|
||||
&Box::new(|path: PathBuf| {
|
||||
&|path: PathBuf| {
|
||||
for (glob, dst) in &globs {
|
||||
if glob.is_match(&path) {
|
||||
return Some(dst.as_path());
|
||||
}
|
||||
}
|
||||
None
|
||||
}),
|
||||
},
|
||||
)
|
||||
.map_err(|e| format!("Unable to move {e:?}"))?;
|
||||
|
||||
|
||||
@@ -1205,7 +1205,6 @@ pub fn fetch_remote(
|
||||
commit_identifier: pkg_toml.commit_identifier.clone(),
|
||||
source_identifier: pkg_toml.source_identifier.clone(),
|
||||
time_identifier: pkg_toml.time_identifier.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
|
||||
+11
-14
@@ -62,7 +62,7 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<
|
||||
|
||||
pub fn move_dir_all_fn<'a>(
|
||||
src: impl AsRef<Path>,
|
||||
mv: &'a Box<impl Fn(PathBuf) -> Option<&'a Path>>,
|
||||
mv: &'a impl Fn(PathBuf) -> Option<&'a Path>,
|
||||
) -> io::Result<()> {
|
||||
move_dir_all_inner_fn(&src, &src, mv)
|
||||
}
|
||||
@@ -70,7 +70,7 @@ pub fn move_dir_all_fn<'a>(
|
||||
fn move_dir_all_inner_fn<'a>(
|
||||
src: impl AsRef<Path>,
|
||||
srcrel: impl AsRef<Path>,
|
||||
mv: &'a Box<impl Fn(PathBuf) -> Option<&'a Path>>,
|
||||
mv: &'a impl Fn(PathBuf) -> Option<&'a Path>,
|
||||
) -> io::Result<()> {
|
||||
let mut files = Vec::new();
|
||||
for entry in fs::read_dir(&src)? {
|
||||
@@ -349,8 +349,8 @@ pub fn read_to_string(path: &Path) -> Result<String> {
|
||||
pub fn get_git_head_rev(dir: &PathBuf) -> Result<(String, bool)> {
|
||||
let git_head = dir.join(".git/HEAD");
|
||||
let head_str = read_to_string(&git_head)?;
|
||||
if head_str.starts_with("ref: ") {
|
||||
let entry = head_str["ref: ".len()..].trim_end();
|
||||
if let Some(stripped) = head_str.strip_prefix("ref: ") {
|
||||
let entry = stripped.trim_end();
|
||||
let git_ref = dir.join(".git").join(entry);
|
||||
let ref_str = if git_ref.is_file() {
|
||||
read_to_string(&git_ref)?
|
||||
@@ -455,11 +455,11 @@ pub fn get_git_remote_tracking(dir: &PathBuf) -> Result<(String, String, String,
|
||||
if line.starts_with('[') {
|
||||
break;
|
||||
}
|
||||
if line.starts_with("remote = ") {
|
||||
remote_name = Some(line["remote = ".len()..].trim().to_string());
|
||||
if let Some(stripped) = line.strip_prefix("remote = ") {
|
||||
remote_name = Some(stripped.trim().to_string());
|
||||
}
|
||||
if line.starts_with("merge = ") {
|
||||
remote_branch = Some(get_git_branch_name(line["merge = ".len()..].trim())?);
|
||||
if let Some(stripped) = line.strip_prefix("merge = ") {
|
||||
remote_branch = Some(get_git_branch_name(stripped.trim())?);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,8 +488,8 @@ pub fn get_git_remote_tracking(dir: &PathBuf) -> Result<(String, String, String,
|
||||
if line.starts_with('[') {
|
||||
break;
|
||||
}
|
||||
if line.starts_with("url = ") {
|
||||
let mut url = line["url = ".len()..].trim();
|
||||
if let Some(stripped) = line.strip_prefix("url = ") {
|
||||
let mut url = stripped.trim();
|
||||
url = chop_dot_git(url);
|
||||
remote_url = Some(url.to_string());
|
||||
}
|
||||
@@ -510,10 +510,7 @@ pub fn get_git_remote_tracking(dir: &PathBuf) -> Result<(String, String, String,
|
||||
}
|
||||
|
||||
pub(crate) fn chop_dot_git(url: &str) -> &str {
|
||||
if url.ends_with(".git") {
|
||||
return &url[..url.len() - ".git".len()];
|
||||
}
|
||||
url
|
||||
url.strip_suffix(".git").unwrap_or(url)
|
||||
}
|
||||
|
||||
fn get_git_branch_name(local_branch_path: &str) -> Result<String> {
|
||||
|
||||
@@ -220,7 +220,6 @@ pub fn package_toml(
|
||||
commit_identifier: ident_source.commit_identifier,
|
||||
source_identifier: ident_source.source_identifier,
|
||||
time_identifier: ident_source.time_identifier,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
serialize_and_write(&toml_path, &package)?;
|
||||
|
||||
+1
-3
@@ -156,9 +156,7 @@ pub struct Recipe {
|
||||
|
||||
impl BuildRecipe {
|
||||
pub fn new(kind: BuildKind) -> Self {
|
||||
let mut build = Self::default();
|
||||
build.kind = kind;
|
||||
build
|
||||
Self { kind, ..Default::default() }
|
||||
}
|
||||
|
||||
pub fn set_as_remote(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user