Skip to content

Commit 8729530

Browse files
author
Stephan Dilly
committed
nightly clippy fixes
1 parent 33344e9 commit 8729530

File tree

6 files changed

+46
-48
lines changed

6 files changed

+46
-48
lines changed

src/app.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -776,19 +776,21 @@ impl App {
776776
}
777777
Action::DeleteBranch(branch_ref, false) => {
778778
self.queue.push(
779-
if let Some(name) = branch_ref.rsplit('/').next()
780-
{
781-
InternalEvent::Push(
782-
name.to_string(),
783-
false,
784-
true,
785-
)
786-
} else {
787-
InternalEvent::ShowErrorMsg(format!(
788-
"Failed to find the branch name in {}",
789-
branch_ref
790-
))
791-
},
779+
branch_ref.rsplit('/').next().map_or_else(
780+
|| {
781+
InternalEvent::ShowErrorMsg(format!(
782+
"Failed to find the branch name in {}",
783+
branch_ref
784+
))
785+
},
786+
|name| {
787+
InternalEvent::Push(
788+
name.to_string(),
789+
false,
790+
true,
791+
)
792+
},
793+
),
792794
);
793795
flags.insert(NeedsUpdate::ALL);
794796
self.select_branch_popup.update_branches()?;

src/components/blame_file.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,23 +354,23 @@ impl BlameFileComponent {
354354

355355
///
356356
fn get_rows(&self, width: usize) -> Vec<Row> {
357-
if let Some(ref file_blame) = self.file_blame {
358-
file_blame
359-
.lines
360-
.iter()
361-
.enumerate()
362-
.map(|(i, (blame_hunk, line))| {
363-
self.get_line_blame(
364-
width,
365-
i,
366-
(blame_hunk.as_ref(), line.as_ref()),
367-
file_blame,
368-
)
369-
})
370-
.collect()
371-
} else {
372-
vec![]
373-
}
357+
self.file_blame
358+
.as_ref()
359+
.map_or_else(Vec::new, |file_blame| {
360+
file_blame
361+
.lines
362+
.iter()
363+
.enumerate()
364+
.map(|(i, (blame_hunk, line))| {
365+
self.get_line_blame(
366+
width,
367+
i,
368+
(blame_hunk.as_ref(), line.as_ref()),
369+
file_blame,
370+
)
371+
})
372+
.collect()
373+
})
374374
}
375375

376376
fn get_line_blame(

src/components/commit_details/details.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl DetailsComponent {
151151

152152
#[allow(unstable_name_collisions, clippy::too_many_lines)]
153153
fn get_text_info(&self) -> Vec<Spans> {
154-
if let Some(ref data) = self.data {
154+
self.data.as_ref().map_or_else(Vec::new, |data| {
155155
let mut res = vec![
156156
Spans::from(vec![
157157
style_detail(&self.theme, &Detail::Author),
@@ -235,9 +235,7 @@ impl DetailsComponent {
235235
}
236236

237237
res
238-
} else {
239-
vec![]
240-
}
238+
})
241239
}
242240

243241
fn move_scroll_top(&mut self, move_type: ScrollType) -> bool {

src/components/commitlist.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,10 @@ impl CommitList {
286286

287287
// commit tags
288288
txt.push(Span::styled(
289-
Cow::from(if let Some(tags) = tags {
290-
format!(" {}", tags)
291-
} else {
292-
String::from("")
293-
}),
289+
Cow::from(tags.map_or_else(
290+
|| String::from(""),
291+
|tags| format!(" {}", tags),
292+
)),
294293
theme.tags(selected),
295294
));
296295

src/components/taglist.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,9 @@ impl TagListComponent {
368368

369369
///
370370
fn get_rows(&self) -> Vec<Row> {
371-
if let Some(ref tags) = self.tags {
371+
self.tags.as_ref().map_or_else(Vec::new, |tags| {
372372
tags.iter().map(|tag| self.get_row(tag)).collect()
373-
} else {
374-
vec![]
375-
}
373+
})
376374
}
377375

378376
///

src/tabs/status.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,16 @@ impl Status {
181181
chunks: &[tui::layout::Rect],
182182
) {
183183
if let Some(branch_name) = self.git_branch_name.last() {
184-
let ahead_behind =
185-
if let Some(state) = &self.git_branch_state {
184+
let ahead_behind = self
185+
.git_branch_state
186+
.as_ref()
187+
.map_or_else(String::new, |state| {
186188
format!(
187189
"\u{2191}{} \u{2193}{} ",
188190
state.ahead, state.behind,
189191
)
190-
} else {
191-
String::new()
192-
};
192+
});
193+
193194
let w = Paragraph::new(format!(
194195
"{}{{{}}}",
195196
ahead_behind, branch_name

0 commit comments

Comments
 (0)