upgrade to rust 1.45 and fix new clippy warnings

This commit is contained in:
Stephan Dilly 2020-07-17 11:54:12 +02:00
parent b82d7af173
commit 0dd50b402e
10 changed files with 35 additions and 29 deletions

View File

@ -3,7 +3,7 @@
#![forbid(unsafe_code)]
#![forbid(missing_docs)]
#![deny(clippy::all)]
#![deny(clippy::result_unwrap_used)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::panic)]
pub mod cached;

View File

@ -219,8 +219,10 @@ fn raw_diff_to_file_diff<'a>(
};
let new_file_diff = if diff.deltas().len() == 1 {
// it's safe to unwrap here because we check first that diff.deltas has a single element.
let delta: DiffDelta = diff.deltas().next().unwrap();
let delta: DiffDelta = diff
.deltas()
.next()
.expect("it's safe to unwrap here because we check first that diff.deltas has a single element");
if delta.status() == Delta::Untracked {
let relative_path =
@ -272,7 +274,10 @@ fn raw_diff_to_file_diff<'a>(
}
if !current_lines.is_empty() {
adder(&current_hunk.unwrap(), &current_lines);
adder(
&current_hunk.expect("invalid hunk"),
&current_lines,
);
}
if new_file_diff {

View File

@ -23,7 +23,8 @@ pub fn stage_hunk(
let mut opt = ApplyOptions::new();
opt.hunk_callback(|hunk| {
let header = HunkHeader::from(hunk.unwrap());
let header =
HunkHeader::from(hunk.expect("hunk unavailable"));
hash(&header) == hunk_hash
});
@ -117,7 +118,8 @@ pub fn unstage_hunk(
let mut hunk_idx = 0;
let mut opt = ApplyOptions::new();
opt.hunk_callback(|_hunk| {
let res = if hunk_idx == hunk_index.unwrap() {
let res = if hunk_idx == hunk_index.expect("invalid hunk")
{
count += 1;
true
} else {

View File

@ -2,7 +2,7 @@
#![forbid(unsafe_code)]
#![forbid(missing_docs)]
#![deny(clippy::result_unwrap_used)]
#![deny(clippy::unwrap_used)]
use std::time::Instant;

View File

@ -109,7 +109,7 @@ impl FileTreeComponent {
if let Some(item) = self.tree.selected_item() {
match item.kind {
FileTreeItemKind::File(_) => true,
_ => false,
FileTreeItemKind::Path(..) => false,
}
} else {
false
@ -206,7 +206,7 @@ impl FileTreeComponent {
StatusItemType::New => '+',
StatusItemType::Deleted => '-',
StatusItemType::Renamed => 'R',
_ => ' ',
StatusItemType::Typechange => ' ',
}
}
}

View File

@ -192,7 +192,8 @@ impl FileTreeItems {
index: usize,
) -> usize {
if let Some(parent_path) = Path::new(path).parent() {
let parent_path = parent_path.to_str().unwrap();
let parent_path =
parent_path.to_str().expect("invalid path");
for i in (0..=index).rev() {
let item = &self.items[i];
let item_path = &item.info.full_path;
@ -216,18 +217,16 @@ impl FileTreeItems {
ancestors.reverse();
for c in &ancestors {
if c.parent().is_some() {
let path_string = String::from(c.to_str().unwrap());
if !paths_added.contains(c) {
paths_added.insert(c);
let is_collapsed =
collapsed.contains(&path_string);
nodes.push(FileTreeItem::new_path(
c,
path_string,
is_collapsed,
)?);
}
if c.parent().is_some() && !paths_added.contains(c) {
paths_added.insert(c);
let path_string =
String::from(c.to_str().expect("invalid path"));
let is_collapsed = collapsed.contains(&path_string);
nodes.push(FileTreeItem::new_path(
c,
path_string,
is_collapsed,
)?);
}
}

View File

@ -332,8 +332,8 @@ impl StatusTree {
inner_collapsed = Some(format!("{}/", &item_path));
}
if prefix.is_none()
|| item_path.starts_with(prefix.unwrap())
if prefix
.map_or(true, |prefix| item_path.starts_with(prefix))
{
self.tree[i].info.visible = true
} else {

View File

@ -2,7 +2,7 @@
#![deny(clippy::cargo)]
#![deny(clippy::pedantic)]
#![deny(clippy::nursery)]
#![deny(clippy::result_unwrap_used)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::panic)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)]
@ -141,8 +141,8 @@ fn main() -> Result<()> {
{
app.update_git(ev)?
}
QueueEvent::GitEvent(..) => (),
QueueEvent::SpinnerUpdate => unreachable!(),
_ => (),
}
draw(&mut terminal, &app)?;

View File

@ -137,7 +137,7 @@ impl Status {
match self.focus {
Focus::WorkDir => self.index_wd.is_file_seleted(),
Focus::Stage => self.index.is_file_seleted(),
_ => false,
Focus::Diff => false,
}
}

View File

@ -110,7 +110,7 @@ impl Theme {
StatusItemType::Renamed => {
Style::default().fg(self.diff_file_moved)
}
_ => Style::default(),
StatusItemType::Typechange => Style::default(),
};
self.apply_select(style, selected)
@ -155,7 +155,7 @@ impl Theme {
DiffLineType::Header => Style::default()
.fg(self.disabled_fg)
.modifier(Modifier::BOLD),
_ => Style::default().fg(if selected {
DiffLineType::None => Style::default().fg(if selected {
self.command_fg
} else {
Color::Reset