From 37da79233aafda6b6c82d039c39860c86a1b10de Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 26 Mar 2020 23:45:52 +0100 Subject: [PATCH] fix tons of clippy warnings --- asyncgit/src/diff.rs | 12 ++++-------- asyncgit/src/sync/utils.rs | 10 +++++----- src/app.rs | 14 ++++++-------- src/components/commit.rs | 6 +++--- src/components/diff.rs | 4 ++-- src/components/index.rs | 2 +- src/ui/mod.rs | 4 ++-- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/asyncgit/src/diff.rs b/asyncgit/src/diff.rs index 3cfa2f63..4ace37ea 100644 --- a/asyncgit/src/diff.rs +++ b/asyncgit/src/diff.rs @@ -40,7 +40,7 @@ impl AsyncDiff { pub fn last(&mut self) -> Option { let last = self.last.lock().unwrap(); if let Some(res) = last.clone() { - Some(res.result.clone()) + Some(res.result) } else { None } @@ -90,8 +90,8 @@ impl AsyncDiff { let mut last = arc_last.lock().unwrap(); *last = Some(LastResult { result: res, - hash: hash, - params: params, + hash, + params, }); } @@ -104,11 +104,7 @@ impl AsyncDiff { } fn get_last_param(&self) -> Option { - self.last - .lock() - .unwrap() - .clone() - .map_or(None, |e| Some(e.params)) + self.last.lock().unwrap().clone().map(|e| e.params) } fn clear_current(&mut self) { diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 1c078234..4fec8957 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -24,7 +24,7 @@ pub fn repo() -> Repository { } /// -pub fn commit(msg: &String) { +pub fn commit(msg: &str) { scope_time!("commit"); let repo = repo(); @@ -41,7 +41,7 @@ pub fn commit(msg: &String) { Some("HEAD"), &signature, &signature, - msg.as_str(), + msg, &tree, &[&parent], ) @@ -68,7 +68,7 @@ pub fn stage_add(path: &Path) -> bool { let flags = IndexAddOption::DISABLE_PATHSPEC_MATCH | IndexAddOption::CHECK_PATHSPEC; - if let Ok(_) = index.add_all(path, flags, cb) { + if index.add_all(path, flags, cb).is_ok() { index.write().unwrap(); return true; } @@ -90,7 +90,7 @@ pub fn stage_reset(path: &Path) -> bool { ) .unwrap(); - if let Ok(_) = repo.reset_default(Some(&obj), &[path]) { + if repo.reset_default(Some(&obj), &[path]).is_ok() { return true; } @@ -107,7 +107,7 @@ pub fn index_reset(path: &Path) -> bool { checkout_opts.remove_untracked(true); checkout_opts.path(&path).force(); - if let Ok(_) = repo.checkout_head(Some(&mut checkout_opts)) { + if repo.checkout_head(Some(&mut checkout_opts)).is_ok() { return true; } diff --git a/src/app.rs b/src/app.rs index 8973d356..b4527838 100644 --- a/src/app.rs +++ b/src/app.rs @@ -237,7 +237,7 @@ impl App { // we dont show the right diff right now, so we need to request if let Some(diff) = self.git_diff.request(diff_params) { - self.diff.update(path.clone(), is_stage, diff); + self.diff.update(path, is_stage, diff); } else { self.diff.clear(); } @@ -245,7 +245,7 @@ impl App { // we are already showing a diff of the right file // maybe the diff changed (outside file change) if let Some(last) = self.git_diff.last() { - self.diff.update(path.clone(), is_stage, last); + self.diff.update(path, is_stage, last); } } } else { @@ -432,13 +432,11 @@ impl App { self.update(); } } - } else { - if let Some(i) = self.index.selection() { - let path = Path::new(i.path.as_str()); + } else if let Some(i) = self.index.selection() { + let path = Path::new(i.path.as_str()); - if sync::stage_reset(path) { - self.update(); - } + if sync::stage_reset(path) { + self.update(); } } } diff --git a/src/components/commit.rs b/src/components/commit.rs index 7e30003f..54e153e9 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -21,7 +21,7 @@ pub struct CommitComponent { impl Component for CommitComponent { fn draw(&self, f: &mut Frame, _rect: Rect) { if self.visible { - let txt = if self.msg.len() > 0 { + let txt = if !self.msg.is_empty() { [Text::Raw(Cow::from(self.msg.clone()))] } else { [Text::Styled( @@ -73,7 +73,7 @@ impl Component for CommitComponent { self.commit(); true } - KeyCode::Backspace if self.msg.len() > 0 => { + KeyCode::Backspace if !self.msg.is_empty() => { self.msg.pop().unwrap(); true } @@ -106,6 +106,6 @@ impl CommitComponent { } fn can_commit(&self) -> bool { - self.msg.len() > 0 + !self.msg.is_empty() } } diff --git a/src/components/diff.rs b/src/components/diff.rs index ba107bcd..b0e3a004 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -60,14 +60,14 @@ impl DiffComponent { self.scroll = self.scroll.checked_add(1).unwrap_or(self.scroll); } else { - self.scroll = self.scroll.checked_sub(1).unwrap_or(0); + self.scroll = self.scroll.saturating_sub(1); } } fn get_text(&self, width: u16, height: u16) -> Vec { let selection = self.scroll; let height_d2 = height / 2; - let min = self.scroll.checked_sub(height_d2).unwrap_or(0); + let min = self.scroll.saturating_sub(height_d2); let max = min + height; let mut res = Vec::new(); diff --git a/src/components/index.rs b/src/components/index.rs index 22f65665..8bce4426 100644 --- a/src/components/index.rs +++ b/src/components/index.rs @@ -41,7 +41,7 @@ impl IndexComponent { self.items = list.clone(); let old_selection = self.selection.unwrap_or_default(); - self.selection = if self.items.len() > 0 { + self.selection = if !self.items.is_empty() { Some(cmp::min(old_selection, self.items.len() - 1)) } else { None diff --git a/src/ui/mod.rs b/src/ui/mod.rs index d707e346..5e3e3cf1 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -59,7 +59,7 @@ pub fn centered_rect_absolute( pub fn draw_list<'b, B: Backend, L>( f: &mut Frame, r: Rect, - title: &'b String, + title: &'b str, items: L, select: Option, selected: bool, @@ -75,7 +75,7 @@ pub fn draw_list<'b, B: Backend, L>( ScrollableList::new(items) .block( Block::default() - .title(title.as_str()) + .title(title) .borders(Borders::ALL) .title_style(style_title) .border_style(style_border),