diff --git a/asyncgit/src/asyncjob/mod.rs b/asyncgit/src/asyncjob/mod.rs index 258faa0e5b..d17d293280 100644 --- a/asyncgit/src/asyncjob/mod.rs +++ b/asyncgit/src/asyncjob/mod.rs @@ -207,7 +207,7 @@ mod test { let res = self.v.fetch_add(self.value_to_add, Ordering::SeqCst); - println!("[job] value: {}", res); + println!("[job] value: {res}"); Ok(()) } @@ -236,8 +236,8 @@ mod test { } println!("recv"); - let _foo = receiver.recv().unwrap(); - let _foo = receiver.recv().unwrap(); + receiver.recv().unwrap(); + receiver.recv().unwrap(); assert!(receiver.is_empty()); assert_eq!( @@ -282,7 +282,7 @@ mod test { wait_for_job(&job); println!("recv"); - let _foo = receiver.recv().unwrap(); + receiver.recv().unwrap(); println!("received"); assert_eq!( diff --git a/asyncgit/src/error.rs b/asyncgit/src/error.rs index 5cbed38b37..9078e3142d 100644 --- a/asyncgit/src/error.rs +++ b/asyncgit/src/error.rs @@ -83,12 +83,12 @@ pub type Result = std::result::Result; impl From> for Error { fn from(error: std::sync::PoisonError) -> Self { - Self::Generic(format!("poison error: {}", error)) + Self::Generic(format!("poison error: {error}")) } } impl From> for Error { fn from(error: crossbeam_channel::SendError) -> Self { - Self::Generic(format!("send error: {}", error)) + Self::Generic(format!("send error: {error}")) } } diff --git a/asyncgit/src/sync/blame.rs b/asyncgit/src/sync/blame.rs index 09d0085519..eba952fcb7 100644 --- a/asyncgit/src/sync/blame.rs +++ b/asyncgit/src/sync/blame.rs @@ -170,10 +170,7 @@ mod tests { let repo_path: &RepoPath = &root.as_os_str().to_str().unwrap().into(); - assert!(matches!( - blame_file(&repo_path, "foo", None), - Err(_) - )); + assert!(matches!(blame_file(repo_path, "foo", None), Err(_))); File::create(&root.join(file_path))? .write_all(b"line 1\n")?; @@ -181,7 +178,7 @@ mod tests { stage_add_file(repo_path, file_path)?; commit(repo_path, "first commit")?; - let blame = blame_file(&repo_path, "foo", None)?; + let blame = blame_file(repo_path, "foo", None)?; assert!(matches!( blame.lines.as_slice(), @@ -205,7 +202,7 @@ mod tests { stage_add_file(repo_path, file_path)?; commit(repo_path, "second commit")?; - let blame = blame_file(&repo_path, "foo", None)?; + let blame = blame_file(repo_path, "foo", None)?; assert!(matches!( blame.lines.as_slice(), @@ -232,14 +229,14 @@ mod tests { file.write(b"line 3\n")?; - let blame = blame_file(&repo_path, "foo", None)?; + let blame = blame_file(repo_path, "foo", None)?; assert_eq!(blame.lines.len(), 2); stage_add_file(repo_path, file_path)?; commit(repo_path, "third commit")?; - let blame = blame_file(&repo_path, "foo", None)?; + let blame = blame_file(repo_path, "foo", None)?; assert_eq!(blame.lines.len(), 3); @@ -264,6 +261,6 @@ mod tests { stage_add_file(repo_path, file_path).unwrap(); commit(repo_path, "first commit").unwrap(); - assert!(blame_file(&repo_path, "bar\\foo", None).is_ok()); + assert!(blame_file(repo_path, "bar\\foo", None).is_ok()); } } diff --git a/asyncgit/src/sync/branch/merge_commit.rs b/asyncgit/src/sync/branch/merge_commit.rs index 50d7dc397f..f3d5bf102c 100644 --- a/asyncgit/src/sync/branch/merge_commit.rs +++ b/asyncgit/src/sync/branch/merge_commit.rs @@ -158,7 +158,7 @@ mod test { false, false, None, - None.into(), + None, ) .is_err()); @@ -195,7 +195,7 @@ mod test { //verify commit msg let details = crate::sync::get_commit_details( &clone2_dir.into(), - merge_commit.into(), + merge_commit, ) .unwrap(); assert_eq!( diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs index 327a3de173..c72a484559 100644 --- a/asyncgit/src/sync/branch/mod.rs +++ b/asyncgit/src/sync/branch/mod.rs @@ -206,7 +206,7 @@ pub(crate) fn branch_set_upstream( if branch.upstream().is_err() { let remote = get_default_remote_in_repo(repo)?; - let upstream_name = format!("{}/{}", remote, branch_name); + let upstream_name = format!("{remote}/{branch_name}"); branch.set_upstream(Some(upstream_name.as_str()))?; } diff --git a/asyncgit/src/sync/branch/rename.rs b/asyncgit/src/sync/branch/rename.rs index 2b648dee1b..90ca31c291 100644 --- a/asyncgit/src/sync/branch/rename.rs +++ b/asyncgit/src/sync/branch/rename.rs @@ -24,7 +24,7 @@ pub fn rename_branch( #[cfg(test)] mod test { - use super::super::*; + use super::super::{checkout_branch, create_branch, RepoPath}; use super::rename_branch; use crate::sync::tests::repo_init; @@ -42,7 +42,7 @@ mod test { assert_eq!( repo.branches(None) .unwrap() - .nth(0) + .next() .unwrap() .unwrap() .0 @@ -58,7 +58,7 @@ mod test { assert_eq!( repo.branches(None) .unwrap() - .nth(0) + .next() .unwrap() .unwrap() .0 diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs index b8754581fb..07d98feb30 100644 --- a/asyncgit/src/sync/commit.rs +++ b/asyncgit/src/sync/commit.rs @@ -138,7 +138,7 @@ mod tests { fn count_commits(repo: &Repository, max: usize) -> usize { let mut items = Vec::new(); - let mut walk = LogWalker::new(&repo, max).unwrap(); + let mut walk = LogWalker::new(repo, max).unwrap(); walk.read(&mut items).unwrap(); items.len() } diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs index 02395d1ea9..e3cc4810e4 100644 --- a/asyncgit/src/sync/commit_details.rs +++ b/asyncgit/src/sync/commit_details.rs @@ -60,7 +60,7 @@ impl CommitMessage { /// pub fn combine(self) -> String { if let Some(body) = self.body { - format!("{}\n{}", self.subject, body) + format!("{}\n{body}", self.subject) } else { self.subject } @@ -82,6 +82,8 @@ pub struct CommitDetails { impl CommitDetails { /// + #[allow(clippy::missing_const_for_fn)] + // clippy doesn't realise indexing a String is not const pub fn short_hash(&self) -> &str { &self.hash[0..7] } diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index 14b24376dd..2c877b9a87 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -164,8 +164,7 @@ mod tests { stage_add_file(repo_path, file_path).unwrap(); let c2 = commit(repo_path, "commit2").unwrap(); - let res = - get_commits_info(repo_path, &vec![c2, c1], 50).unwrap(); + let res = get_commits_info(repo_path, &[c2, c1], 50).unwrap(); assert_eq!(res.len(), 2); assert_eq!(res[0].message.as_str(), "commit2"); @@ -187,7 +186,7 @@ mod tests { stage_add_file(repo_path, file_path).unwrap(); let c1 = commit(repo_path, "subject\nbody").unwrap(); - let res = get_commits_info(repo_path, &vec![c1], 50).unwrap(); + let res = get_commits_info(repo_path, &[c1], 50).unwrap(); assert_eq!(res.len(), 1); assert_eq!(res[0].message.as_str(), "subject"); @@ -211,7 +210,7 @@ mod tests { let res = get_commits_info( repo_path, - &vec![get_head_repo(&repo).unwrap().into()], + &[get_head_repo(&repo).unwrap()], 50, ) .unwrap(); diff --git a/asyncgit/src/sync/hooks.rs b/asyncgit/src/sync/hooks.rs index 5265632b1a..3a4b3758fa 100644 --- a/asyncgit/src/sync/hooks.rs +++ b/asyncgit/src/sync/hooks.rs @@ -87,7 +87,7 @@ impl HookPaths { } else { let err = String::from_utf8_lossy(&output.stderr); let out = String::from_utf8_lossy(&output.stdout); - let formatted = format!("{}{}", out, err); + let formatted = format!("{out}{err}"); Ok(HookResult::NotOk(formatted)) } @@ -324,7 +324,7 @@ exit 1 let workdir = TempDir::new().unwrap(); let git_root = git_root.into_path(); let repo_path = &RepoPath::Workdir { - gitdir: dbg!(git_root.to_path_buf()), + gitdir: dbg!(git_root), workdir: dbg!(workdir.into_path()), }; @@ -541,7 +541,7 @@ exit 1 let workdir = TempDir::new().unwrap(); let git_root = git_root.into_path(); let repo_path = &RepoPath::Workdir { - gitdir: dbg!(git_root.to_path_buf()), + gitdir: dbg!(git_root), workdir: dbg!(workdir.path().to_path_buf()), }; diff --git a/asyncgit/src/sync/logwalker.rs b/asyncgit/src/sync/logwalker.rs index 15873e2931..3f9110b1d9 100644 --- a/asyncgit/src/sync/logwalker.rs +++ b/asyncgit/src/sync/logwalker.rs @@ -162,7 +162,7 @@ mod tests { walk.read(&mut items).unwrap(); assert_eq!(items.len(), 1); - assert_eq!(items[0], oid2.into()); + assert_eq!(items[0], oid2); Ok(()) } @@ -190,7 +190,7 @@ mod tests { dbg!(&info); assert_eq!(items.len(), 2); - assert_eq!(items[0], oid2.into()); + assert_eq!(items[0], oid2); let mut items = Vec::new(); walk.read(&mut items).unwrap(); @@ -235,7 +235,7 @@ mod tests { walker.read(&mut items).unwrap(); assert_eq!(items.len(), 1); - assert_eq!(items[0], second_commit_id.into()); + assert_eq!(items[0], second_commit_id); let mut items = Vec::new(); walker.read(&mut items).unwrap(); diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 7a72b69f2e..ed305b4a8d 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -125,10 +125,10 @@ mod tests { let temp_dir = TempDir::new().unwrap(); let path = temp_dir.path(); - set_search_path(ConfigLevel::System, &path).unwrap(); - set_search_path(ConfigLevel::Global, &path).unwrap(); - set_search_path(ConfigLevel::XDG, &path).unwrap(); - set_search_path(ConfigLevel::ProgramData, &path).unwrap(); + set_search_path(ConfigLevel::System, path).unwrap(); + set_search_path(ConfigLevel::Global, path).unwrap(); + set_search_path(ConfigLevel::XDG, path).unwrap(); + set_search_path(ConfigLevel::ProgramData, path).unwrap(); }); } @@ -279,7 +279,7 @@ mod tests { .try_init(); } - /// Same as repo_init, but the repo is a bare repo (--bare) + /// Same as `repo_init`, but the repo is a bare repo (--bare) pub fn repo_init_bare() -> Result<(TempDir, Repository)> { init_log(); @@ -303,7 +303,7 @@ mod tests { /// pub fn debug_cmd_print(path: &RepoPath, cmd: &str) { let cmd = debug_cmd(path, cmd); - eprintln!("\n----\n{}", cmd); + eprintln!("\n----\n{cmd}"); } /// helper to fetch commmit details using log walker @@ -323,7 +323,7 @@ mod tests { fn debug_cmd(path: &RepoPath, cmd: &str) -> String { let output = if cfg!(target_os = "windows") { Command::new("cmd") - .args(&["/C", cmd]) + .args(["/C", cmd]) .current_dir(path.gitpath()) .output() .unwrap() @@ -343,12 +343,12 @@ mod tests { if stdout.is_empty() { String::new() } else { - format!("out:\n{}", stdout) + format!("out:\n{stdout}") }, if stderr.is_empty() { String::new() } else { - format!("err:\n{}", stderr) + format!("err:\n{stderr}") } ) } diff --git a/asyncgit/src/sync/rebase.rs b/asyncgit/src/sync/rebase.rs index 8040ee9650..a21438ee88 100644 --- a/asyncgit/src/sync/rebase.rs +++ b/asyncgit/src/sync/rebase.rs @@ -202,7 +202,7 @@ mod test_conflict_free_rebase { .find_commit(c.into()) .unwrap() .parent_ids() - .map(|id| CommitId::from(id)) + .map(CommitId::from) .collect(); foo diff --git a/asyncgit/src/sync/remotes/mod.rs b/asyncgit/src/sync/remotes/mod.rs index 228206fd60..d17df4c69c 100644 --- a/asyncgit/src/sync/remotes/mod.rs +++ b/asyncgit/src/sync/remotes/mod.rs @@ -216,7 +216,7 @@ mod tests { debug_cmd_print( repo_path, - &format!("git remote add second {}", remote_path)[..], + &format!("git remote add second {remote_path}")[..], ); let remotes = get_remotes(repo_path).unwrap(); @@ -251,7 +251,7 @@ mod tests { debug_cmd_print( repo_path, - &format!("git remote add origin {}", remote_path)[..], + &format!("git remote add origin {remote_path}")[..], ); //NOTE: aparently remotes are not chronolically sorted but alphabetically @@ -287,7 +287,7 @@ mod tests { debug_cmd_print( repo_path, - &format!("git remote add someremote {}", remote_path)[..], + &format!("git remote add someremote {remote_path}")[..], ); let remotes = get_remotes(repo_path).unwrap(); diff --git a/asyncgit/src/sync/remotes/push.rs b/asyncgit/src/sync/remotes/push.rs index 7467b5fe75..5e75eda8f9 100644 --- a/asyncgit/src/sync/remotes/push.rs +++ b/asyncgit/src/sync/remotes/push.rs @@ -164,7 +164,7 @@ pub fn push_raw( }; let branch_name = - format!("{}refs/{}/{}", branch_modifier, ref_type, branch); + format!("{branch_modifier}refs/{ref_type}/{branch}"); remote.push(&[branch_name.as_str()], Some(&mut options))?; if let Some((reference, msg)) = @@ -488,11 +488,9 @@ mod tests { upstream_repo .branches(None) .unwrap() - .map(|i| i.unwrap()) + .map(std::result::Result::unwrap) .map(|(i, _)| i.name().unwrap().unwrap().to_string()) - .filter(|i| i == "test_branch") - .next() - .is_some(), + .any(|i| &i == "test_branch"), true ); @@ -516,11 +514,9 @@ mod tests { upstream_repo .branches(None) .unwrap() - .map(|i| i.unwrap()) + .map(std::result::Result::unwrap) .map(|(i, _)| i.name().unwrap().unwrap().to_string()) - .filter(|i| i == "test_branch") - .next() - .is_some(), + .any(|i| &i == "test_branch"), false ); } diff --git a/asyncgit/src/sync/remotes/tags.rs b/asyncgit/src/sync/remotes/tags.rs index 235ababc18..138977b811 100644 --- a/asyncgit/src/sync/remotes/tags.rs +++ b/asyncgit/src/sync/remotes/tags.rs @@ -89,7 +89,7 @@ pub fn tags_missing_remote( let mut local_tags = tags .iter() - .filter_map(|tag| tag.map(|tag| format!("refs/tags/{}", tag))) + .filter_map(|tag| tag.map(|tag| format!("refs/tags/{tag}"))) .collect::>(); let remote_tags = remote_tag_refs(repo_path, remote, basic_credential)?; diff --git a/asyncgit/src/sync/staging/stage_tracked.rs b/asyncgit/src/sync/staging/stage_tracked.rs index 5f9861a131..5d02cf2199 100644 --- a/asyncgit/src/sync/staging/stage_tracked.rs +++ b/asyncgit/src/sync/staging/stage_tracked.rs @@ -163,7 +163,7 @@ c = 4"; assert_eq!(get_statuses(path), (1, 0)); - stage_add_file(path, &Path::new("test.txt")).unwrap(); + stage_add_file(path, Path::new("test.txt")).unwrap(); assert_eq!(get_statuses(path), (0, 1)); diff --git a/asyncgit/src/sync/tags.rs b/asyncgit/src/sync/tags.rs index 700c46fd51..34d0f2d1d1 100644 --- a/asyncgit/src/sync/tags.rs +++ b/asyncgit/src/sync/tags.rs @@ -20,6 +20,8 @@ pub struct Tag { impl Tag { /// + #[allow(clippy::missing_const_for_fn)] + // clippy doesn't realise allocating a String is not const pub fn new(name: &str) -> Self { Self { name: name.into(), diff --git a/src/app.rs b/src/app.rs index 894373bc03..56fe2a5026 100644 --- a/src/app.rs +++ b/src/app.rs @@ -448,7 +448,7 @@ impl App { if let Err(e) = result { let msg = - format!("failed to launch editor:\n{}", e); + format!("failed to launch editor:\n{e}"); log::error!("{}", msg.as_str()); self.msg.show_error(msg.as_str())?; } diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index a23933d193..64c8fc8e31 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -609,7 +609,7 @@ impl BranchListComponent { }; let span_prefix = Span::styled( - format!("{}{} ", is_head_str, upstream_tracking_str), + format!("{is_head_str}{upstream_tracking_str} "), theme.commit_author(selected), ); let span_hash = Span::styled( diff --git a/src/components/commit.rs b/src/components/commit.rs index 8f5c193d49..70d67daff3 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -94,7 +94,7 @@ impl CommitComponent { fn draw_branch_name(&self, f: &mut Frame) { if let Some(name) = self.git_branch_name.last() { - let w = Paragraph::new(format!("{{{}}}", name)) + let w = Paragraph::new(format!("{{{name}}}")) .alignment(Alignment::Right); let rect = { diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 0a901b032d..ec92b123f0 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -366,7 +366,7 @@ impl CommitList { txt.push(splitter.clone()); let author_width = - (width.saturating_sub(19) / 3).max(3).min(20); + (width.saturating_sub(19) / 3).clamp(3, 20); let author = string_width_align(&e.author, author_width); // commit author @@ -399,7 +399,7 @@ impl CommitList { // commit msg txt.push(Span::styled( - format!("{:w$}", &e.msg, w = message_width), + format!("{:message_width$}", &e.msg), theme.text(true, selected), )); @@ -434,7 +434,7 @@ impl CommitList { let branches = self.branches.get(&e.id).map(|names| { names .iter() - .map(|name| format!("{{{}}}", name)) + .map(|name| format!("{{{name}}}")) .join(" ") }); @@ -502,7 +502,7 @@ impl DrawableComponent for CommitList { )); let branch_post_fix = - self.branch.as_ref().map(|b| format!("- {{{}}}", b)); + self.branch.as_ref().map(|b| format!("- {{{b}}}")); let title = format!( "{} {}/{} {}", diff --git a/src/components/create_branch.rs b/src/components/create_branch.rs index a5c784ff72..393eb54e42 100644 --- a/src/components/create_branch.rs +++ b/src/components/create_branch.rs @@ -142,7 +142,7 @@ impl CreateBranchComponent { Err(e) => { log::error!("create branch: {}", e,); self.queue.push(InternalEvent::ShowErrorMsg( - format!("create branch error:\n{}", e,), + format!("create branch error:\n{e}",), )); } } diff --git a/src/components/diff.rs b/src/components/diff.rs index 7361c7b7fa..95d46e7419 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -198,7 +198,7 @@ impl DiffComponent { fn move_selection(&mut self, move_type: ScrollType) { if let Some(diff) = &self.diff { - let max = diff.lines.saturating_sub(1) as usize; + let max = diff.lines.saturating_sub(1); let new_start = match move_type { ScrollType::Down => { @@ -229,7 +229,7 @@ impl DiffComponent { fn update_selection(&mut self, new_start: usize) { if let Some(diff) = &self.diff { - let max = diff.lines.saturating_sub(1) as usize; + let max = diff.lines.saturating_sub(1); let new_start = cmp::min(max, new_start); self.selection = Selection::Single(new_start); self.selected_hunk = @@ -303,9 +303,8 @@ impl DiffComponent { if let Some(diff) = &self.diff { if diff.hunks.is_empty() { let is_positive = diff.size_delta >= 0; - let delta_byte_size = ByteSize::b( - diff.size_delta.unsigned_abs() as u64, - ); + let delta_byte_size = + ByteSize::b(diff.size_delta.unsigned_abs()); let sign = if is_positive { "+" } else { "-" }; res.extend(vec![Spans::from(vec![ Span::raw(Cow::from("size: ")), @@ -378,7 +377,7 @@ impl DiffComponent { .selection .contains(line_cursor), hunk_selected, - i == hunk_len as usize - 1, + i == hunk_len - 1, &self.theme, )); lines_added += 1; diff --git a/src/components/file_revlog.rs b/src/components/file_revlog.rs index 563ee04dbb..cabe364f1b 100644 --- a/src/components/file_revlog.rs +++ b/src/components/file_revlog.rs @@ -231,7 +231,7 @@ impl FileRevlogComponent { let commits = get_commits_info( &self.repo_path.borrow(), &git_log.get_slice(start, SLICE_SIZE)?, - self.current_width.get() as usize, + self.current_width.get(), ); if let Ok(commits) = commits { diff --git a/src/components/options_popup.rs b/src/components/options_popup.rs index cfc9e51e99..09a98501d3 100644 --- a/src/components/options_popup.rs +++ b/src/components/options_popup.rs @@ -134,7 +134,7 @@ impl OptionsPopupComponent { self.theme.text(true, false), ), Span::styled( - format!("{:^w$}", value, w = half), + format!("{value:^half$}"), self.theme.text(true, selected), ), ])); diff --git a/src/components/pull.rs b/src/components/pull.rs index cfc1d7eb32..4ac525fa49 100644 --- a/src/components/pull.rs +++ b/src/components/pull.rs @@ -118,7 +118,7 @@ impl PullComponent { self.pending = false; self.hide(); self.queue.push(InternalEvent::ShowErrorMsg( - format!("fetch failed:\n{}", error), + format!("fetch failed:\n{error}"), )); } } diff --git a/src/components/push.rs b/src/components/push.rs index 9ed2a137b3..a8295a7e3f 100644 --- a/src/components/push.rs +++ b/src/components/push.rs @@ -181,7 +181,7 @@ impl PushComponent { if !self.pending { if let Some(err) = self.git_push.last_result()? { self.queue.push(InternalEvent::ShowErrorMsg( - format!("push failed:\n{}", err), + format!("push failed:\n{err}"), )); } self.hide(); diff --git a/src/components/push_tags.rs b/src/components/push_tags.rs index 9ab9c78e94..0d5e9a048e 100644 --- a/src/components/push_tags.rs +++ b/src/components/push_tags.rs @@ -123,7 +123,7 @@ impl PushTagsComponent { if !self.pending { if let Some(err) = self.git_push.last_result()? { self.queue.push(InternalEvent::ShowErrorMsg( - format!("push tags failed:\n{}", err), + format!("push tags failed:\n{err}"), )); } self.hide(); diff --git a/src/components/rename_branch.rs b/src/components/rename_branch.rs index a519bf4de9..08215e4fb4 100644 --- a/src/components/rename_branch.rs +++ b/src/components/rename_branch.rs @@ -144,7 +144,7 @@ impl RenameBranchComponent { Err(e) => { log::error!("create branch: {}", e,); self.queue.push(InternalEvent::ShowErrorMsg( - format!("rename branch error:\n{}", e,), + format!("rename branch error:\n{e}",), )); } } diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index 06a94120d8..6b5a25f208 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -167,7 +167,7 @@ impl StatusTreeComponent { let indent_str = if indent == 0 { String::new() } else { - format!("{:w$}", " ", w = (indent as usize) * 2) + format!("{:w$}", " ", w = indent * 2) }; if !visible { @@ -192,7 +192,7 @@ impl StatusTreeComponent { w = width as usize ) } else { - format!("{} {}{}", status_char, indent_str, file) + format!("{status_char} {indent_str}{file}") }; Some(Span::styled( diff --git a/src/components/submodules.rs b/src/components/submodules.rs index 06c7c26c98..b14fc6ca45 100644 --- a/src/components/submodules.rs +++ b/src/components/submodules.rs @@ -387,7 +387,7 @@ impl SubmodulesListComponent { ); let span_name = Span::styled( - format!("{:w$} ", module_path, w = name_length), + format!("{module_path:name_length$} "), theme.text(true, selected), ); diff --git a/src/components/tag_commit.rs b/src/components/tag_commit.rs index 464fab6db4..cf82dfa3fd 100644 --- a/src/components/tag_commit.rs +++ b/src/components/tag_commit.rs @@ -194,7 +194,7 @@ impl TagCommitComponent { log::error!("e: {}", e,); self.queue.push(InternalEvent::ShowErrorMsg( - format!("tag error:\n{}", e,), + format!("tag error:\n{e}",), )); } } diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 250c882278..2d59a41fce 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -305,7 +305,7 @@ impl TextInputComponent { fn draw_char_count(&self, f: &mut Frame, r: Rect) { let count = self.msg.len(); if count > 0 { - let w = Paragraph::new(format!("[{} chars]", count)) + let w = Paragraph::new(format!("[{count} chars]")) .alignment(Alignment::Right); let mut rect = { diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index a87a96f0b2..17a52e2012 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -55,7 +55,7 @@ impl LogEntry { } else { format!("{:0>2}m ago", delta.num_minutes()) }; - format!("{: <10}", delta_str) + format!("{delta_str: <10}") } else if self.time.date() == now.date() { self.time.format("%T ").to_string() } else { diff --git a/src/components/utils/mod.rs b/src/components/utils/mod.rs index 2041346f71..9f6a70a9df 100644 --- a/src/components/utils/mod.rs +++ b/src/components/utils/mod.rs @@ -47,11 +47,11 @@ pub fn string_width_align(s: &str, width: usize) -> String { if (len >= width_wo_postfix && len <= width) || (len <= width_wo_postfix) { - format!("{:w$}", s, w = width) + format!("{s:width$}") } else { let mut s = s.to_string(); s.truncate(find_truncate_point(&s, width_wo_postfix)); - format!("{}{}", s, POSTFIX) + format!("{s}{POSTFIX}") } } diff --git a/src/components/utils/statustree.rs b/src/components/utils/statustree.rs index 1edc7ce614..925958430e 100644 --- a/src/components/utils/statustree.rs +++ b/src/components/utils/statustree.rs @@ -352,7 +352,7 @@ impl StatusTree { *collapsed = true; } - let path = format!("{}/", path); + let path = format!("{path}/"); for i in index + 1..self.tree.len() { let item = &mut self.tree[i]; @@ -373,7 +373,7 @@ impl StatusTree { *collapsed = false; } - let path = format!("{}/", path); + let path = format!("{path}/"); self.update_visibility( Some(path.as_str()), diff --git a/src/main.rs b/src/main.rs index d36e7285bb..a6c24d50cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ clippy::bool_to_int_with_if, clippy::module_name_repetitions )] +#![allow(clippy::missing_const_for_fn)] // high number of false positives on nightly + //TODO: // #![deny(clippy::expect_used)] @@ -121,10 +123,10 @@ fn main() -> Result<()> { } let key_config = KeyConfig::init() - .map_err(|e| eprintln!("KeyConfig loading error: {}", e)) + .map_err(|e| eprintln!("KeyConfig loading error: {e}")) .unwrap_or_default(); let theme = Theme::init(&cliargs.theme) - .map_err(|e| eprintln!("Theme loading error: {}", e)) + .map_err(|e| eprintln!("Theme loading error: {e}")) .unwrap_or_default(); setup_terminal()?; @@ -256,13 +258,13 @@ fn shutdown_terminal() { io::stdout().execute(LeaveAlternateScreen).map(|_f| ()); if let Err(e) = leave_screen { - eprintln!("leave_screen failed:\n{}", e); + eprintln!("leave_screen failed:\n{e}"); } let leave_raw_mode = disable_raw_mode(); if let Err(e) = leave_raw_mode { - eprintln!("leave_raw_mode failed:\n{}", e); + eprintln!("leave_raw_mode failed:\n{e}"); } } diff --git a/src/strings.rs b/src/strings.rs index bb76aca2b6..fcfeadee08 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -110,7 +110,7 @@ pub fn commit_msg(_key_config: &SharedKeyConfig) -> String { "type commit message..".to_string() } pub fn commit_first_line_warning(count: usize) -> String { - format!("[subject length: {}]", count) + format!("[subject length: {count}]") } pub const fn branch_name_invalid() -> &'static str { "[invalid name]" @@ -157,9 +157,9 @@ pub fn confirm_msg_merge( rebase: bool, ) -> String { if rebase { - format!("Rebase onto {} incoming commits?", incoming) + format!("Rebase onto {incoming} incoming commits?") } else { - format!("Merge of {} incoming commits?", incoming) + format!("Merge of {incoming} incoming commits?") } } @@ -225,7 +225,7 @@ pub fn confirm_msg_delete_branch( _key_config: &SharedKeyConfig, branch_ref: &str, ) -> String { - format!("Confirm deleting branch: '{}' ?", branch_ref) + format!("Confirm deleting branch: '{branch_ref}' ?") } pub fn confirm_title_delete_remote_branch( _key_config: &SharedKeyConfig, @@ -236,7 +236,7 @@ pub fn confirm_msg_delete_remote_branch( _key_config: &SharedKeyConfig, branch_ref: &str, ) -> String { - format!("Confirm deleting remote branch: '{}' ?", branch_ref) + format!("Confirm deleting remote branch: '{branch_ref}' ?") } pub fn confirm_title_delete_tag( _key_config: &SharedKeyConfig, @@ -247,13 +247,13 @@ pub fn confirm_msg_delete_tag( _key_config: &SharedKeyConfig, tag_name: &str, ) -> String { - format!("Confirm deleting Tag: '{}' ?", tag_name) + format!("Confirm deleting Tag: '{tag_name}' ?") } pub fn confirm_title_delete_tag_remote() -> String { "Delete Tag (remote)".to_string() } pub fn confirm_msg_delete_tag_remote(remote_name: &str) -> String { - format!("Confirm deleting tag on remote '{}'?", remote_name) + format!("Confirm deleting tag on remote '{remote_name}'?") } pub fn confirm_title_force_push( _key_config: &SharedKeyConfig, @@ -292,7 +292,7 @@ pub fn tag_popup_name_msg() -> String { "type tag name".to_string() } pub fn tag_popup_annotation_title(name: &str) -> String { - format!("Tag Annotation ({})", name) + format!("Tag Annotation ({name})") } pub fn tag_popup_annotation_msg() -> String { "type tag annotation".to_string() @@ -378,7 +378,7 @@ pub mod commit { old: bool, hash: &str, ) -> String { - format!("{}: {}", if old { "Old" } else { "New" }, hash) + format!("{}: {hash}", if old { "Old" } else { "New" }) } pub fn details_message_title( _key_config: &SharedKeyConfig, @@ -1065,7 +1065,7 @@ pub mod commands { if marked == 0 { String::default() } else { - format!(" {}", marked) + format!(" {marked}") }, key_config.get_hint(key_config.keys.stash_drop), ), diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index 1d61d988ac..fbdf0fe25d 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -68,7 +68,7 @@ impl StashList { } Err(e) => { self.queue.push(InternalEvent::ShowErrorMsg( - format!("stash apply error:\n{}", e,), + format!("stash apply error:\n{e}",), )); } } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 609c6c6186..eab771df74 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -290,7 +290,7 @@ impl Status { .unwrap_or_default(), ) } - _ => format!("{:?}", state), + _ => format!("{state:?}"), } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index cee73105ba..8f11dc9ba2 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -87,8 +87,8 @@ pub fn centered_rect( /// makes sure Rect `r` at least stays as big as min and not bigger than max pub fn rect_inside(min: Size, max: Size, r: Rect) -> Rect { - let new_width = r.width.max(min.width).min(max.width); - let new_height = r.height.max(min.height).min(max.height); + let new_width = r.width.clamp(min.width, max.width); + let new_height = r.height.clamp(min.height, max.height); let diff_width = new_width.saturating_sub(r.width); let diff_height = new_height.saturating_sub(r.height); diff --git a/src/ui/reflow.rs b/src/ui/reflow.rs index b2417867a5..a9937361e6 100644 --- a/src/ui/reflow.rs +++ b/src/ui/reflow.rs @@ -442,7 +442,7 @@ mod test { assert_eq!(line_truncator, vec!["", "a"]); } - /// Tests WordWrapper with words some of which exceed line length and some not. + /// Tests `WordWrapper` with words some of which exceed line length and some not. #[test] fn line_composer_word_wrapper_mixed_length() { let width = 20; @@ -471,11 +471,11 @@ mod test { では、"; let (word_wrapper, word_wrapper_width) = run_composer( Composer::WordWrapper { trim: true }, - &text, + text, width, ); let (line_truncator, _) = - run_composer(Composer::LineTruncator, &text, width); + run_composer(Composer::LineTruncator, text, width); assert_eq!(line_truncator, vec!["コンピュータ上で文字"]); let wrapped = vec![ "コンピュータ上で文字", @@ -592,7 +592,7 @@ mod test { ); // Ensure that if the character was a regular space, it would be wrapped differently. - let text_space = text.replace("\u{00a0}", " "); + let text_space = text.replace('\u{00a0}', " "); let (word_wrapper_space, _) = run_composer( Composer::WordWrapper { trim: true }, &text_space,