Fix clippy warnings

This commit is contained in:
Austen Adler 2022-06-09 18:11:03 -04:00
parent 01a7063c22
commit d6a3fccd41
5 changed files with 24 additions and 26 deletions

View File

@ -43,7 +43,7 @@ impl ToString for KakError {
Self::KakResponse(_) => "Invalid kak response", Self::KakResponse(_) => "Invalid kak response",
Self::Io(_) => "IO error", Self::Io(_) => "IO error",
Self::NotImplemented(_) => "Not Implemented", Self::NotImplemented(_) => "Not Implemented",
Self::Custom(s) => &s, Self::Custom(s) => s,
} }
) )
} }

View File

@ -59,9 +59,7 @@ pub fn get_selections_with_desc() -> Result<Vec<SelectionWithDesc>, KakError> {
} }
let min_selection = selections_desc.iter().min().ok_or_else(|| { let min_selection = selections_desc.iter().min().ok_or_else(|| {
KakError::KakResponse(format!( KakError::KakResponse("Selections are empty, which should not be possible".to_string())
"Selections are empty, which should not be possible"
))
})?; })?;
// Kakoune prints selections in file order, but prints selections_desc rotated based on current selection // Kakoune prints selections in file order, but prints selections_desc rotated based on current selection

View File

@ -33,7 +33,7 @@ enum Operation {
} }
impl Operation { impl Operation {
pub fn to_char(&self) -> char { pub const fn to_char(&self) -> char {
match self { match self {
Self::Intersect => '&', Self::Intersect => '&',
Self::Subtract => '-', Self::Subtract => '-',
@ -181,8 +181,8 @@ fn compare(
)?; )?;
for k in key_set_operation_result { for k in key_set_operation_result {
let left_count = left_ordered_counts.get(&k as &str).unwrap_or(&0); let left_count = left_ordered_counts.get(k as &str).unwrap_or(&0);
let right_count = right_ordered_counts.get(&k as &str).unwrap_or(&0); let right_count = right_ordered_counts.get(k as &str).unwrap_or(&0);
write!( write!(
f, f,
@ -217,7 +217,7 @@ fn compare(
fn to_ordered_counts(options: &Options, sels: Vec<Selection>) -> LinkedHashMap<Selection, usize> { fn to_ordered_counts(options: &Options, sels: Vec<Selection>) -> LinkedHashMap<Selection, usize> {
let mut ret = LinkedHashMap::new(); let mut ret = LinkedHashMap::new();
for i in sels.into_iter() { for i in sels {
let key = if options.no_trim { let key = if options.no_trim {
i i
} else { } else {
@ -242,22 +242,22 @@ fn key_set_operation<'a>(
) -> LinkedHashSet<&'a Selection> { ) -> LinkedHashSet<&'a Selection> {
match operation { match operation {
Operation::Intersect => left_keys Operation::Intersect => left_keys
.intersection(&right_keys) .intersection(right_keys)
// .into_iter() // .into_iter()
// TODO: Remove this // TODO: Remove this
.cloned() .copied()
.collect(), .collect(),
Operation::Subtract => left_keys Operation::Subtract => left_keys
.difference(&right_keys) .difference(right_keys)
.into_iter() .into_iter()
// TODO: Remove this // TODO: Remove this
.cloned() .copied()
.collect(), .collect(),
Operation::Compare | Operation::Union => left_keys Operation::Compare | Operation::Union => left_keys
.union(&right_keys) .union(right_keys)
.into_iter() .into_iter()
// TODO: Remove this // TODO: Remove this
.cloned() .copied()
.collect(), .collect(),
// TODO: Symmetric difference? // TODO: Symmetric difference?
} }
@ -268,11 +268,11 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K
// They gave us something like "a-b" or "c?d" // They gave us something like "a-b" or "c?d"
args.iter() args.iter()
.flat_map(|s: &String| s.trim().chars()) .flat_map(|s: &String| s.trim().chars())
.map(|c| String::from(c)) .map(String::from)
.collect::<Vec<String>>() .collect::<Vec<String>>()
} else { } else {
// They gave us something like "a - b" or "c compare d" // They gave us something like "a - b" or "c compare d"
args.iter().cloned().collect() args.to_vec()
}; };
let (left_register, middle, right_register) = match &args[..] { let (left_register, middle, right_register) = match &args[..] {
[l, r] => { [l, r] => {
@ -285,9 +285,9 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K
(Ok(_), Ok(_)) => Err(KakError::Custom(format!( (Ok(_), Ok(_)) => Err(KakError::Custom(format!(
"Arguments '{l}' and '{r}' cannot both be operations" "Arguments '{l}' and '{r}' cannot both be operations"
))), ))),
(Err(_), Err(_)) => Err(KakError::Custom(format!( (Err(_), Err(_)) => Err(KakError::Custom(
"One argument must be an operation" "One argument must be an operation".to_string(),
))), )),
} }
} }
[l, middle, r] => { [l, middle, r] => {
@ -298,9 +298,9 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K
Register::from_str(r)?, Register::from_str(r)?,
)) ))
} }
_ => Err(KakError::Custom(format!( _ => Err(KakError::Custom(
"Invalid arguments to set command" "Invalid arguments to set command".to_string(),
))), )),
}?; }?;
if left_register == right_register { if left_register == right_register {

View File

@ -104,13 +104,13 @@ fn to_sortable_selection<'a, 'b>(
) -> SortableSelection<'a> { ) -> SortableSelection<'a> {
if options.no_skip_whitespace { if options.no_skip_whitespace {
SortableSelection { SortableSelection {
selection: &selection, selection,
content_comparison: selection.content.as_str(), content_comparison: selection.content.as_str(),
subselections: vec![], subselections: vec![],
} }
} else { } else {
SortableSelection { SortableSelection {
selection: &selection, selection,
content_comparison: selection.content.as_str().trim(), content_comparison: selection.content.as_str().trim(),
subselections: vec![], subselections: vec![],
} }

View File

@ -5,7 +5,7 @@ use std::{
hash::{Hash, Hasher}, hash::{Hash, Hasher},
}; };
pub(crate) fn get_key( pub fn get_key(
selection: &Selection, selection: &Selection,
skip_whitespace: bool, skip_whitespace: bool,
regex: Option<&Regex>, regex: Option<&Regex>,
@ -40,7 +40,7 @@ pub(crate) fn get_key(
} }
/// Get a key out of a selection based on options /// Get a key out of a selection based on options
pub(crate) fn get_hash( pub fn get_hash(
selection: &Selection, selection: &Selection,
skip_whitespace: bool, skip_whitespace: bool,
regex: Option<&Regex>, regex: Option<&Regex>,