From 94bd84b45d53b0e0fae52198fbdc05179b87cccc Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 11 Sep 2022 15:19:40 +0300 Subject: [PATCH] Fix clippy lints for `meli` crate --- build.rs | 2 +- src/components.rs | 2 +- src/components/contacts/contact_list.rs | 2 +- src/components/mail/compose.rs | 12 ++++++------ src/components/mail/compose/edit_attachments.rs | 2 +- src/components/mail/listing.rs | 8 ++++---- src/components/mail/listing/conversations.rs | 2 +- src/components/mail/listing/thread.rs | 3 ++- src/components/mail/view.rs | 7 ++++--- src/components/mail/view/envelope.rs | 6 +++--- src/components/mail/view/html.rs | 2 +- src/components/notifications.rs | 13 +++++++------ src/components/utilities.rs | 2 +- src/components/utilities/dialogs.rs | 2 +- src/components/utilities/widgets.rs | 8 ++++---- src/conf.rs | 4 ++-- src/conf/accounts.rs | 4 ++-- src/conf/themes.rs | 17 ++++++++++------- src/plugins.rs | 2 +- src/terminal/color.rs | 2 +- src/terminal/embed/grid.rs | 2 +- src/terminal/keys.rs | 4 ++-- src/terminal/position.rs | 2 +- src/terminal/text_editing.rs | 2 +- src/types.rs | 2 +- 25 files changed, 60 insertions(+), 54 deletions(-) diff --git a/build.rs b/build.rs index db02bb61d..0c181ec2e 100644 --- a/build.rs +++ b/build.rs @@ -39,7 +39,7 @@ fn main() { { use flate2::Compression; use flate2::GzBuilder; - const MANDOC_OPTS: &[&'static str] = &["-T", "utf8", "-I", "os=Generated by mandoc(1)"]; + const MANDOC_OPTS: &[&str] = &["-T", "utf8", "-I", "os=Generated by mandoc(1)"]; use std::env; use std::fs::File; use std::io::prelude::*; diff --git a/src/components.rs b/src/components.rs index 6aa1a9ad1..ba0b78e0a 100644 --- a/src/components.rs +++ b/src/components.rs @@ -66,7 +66,7 @@ pub enum PageMovement { End, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ScrollContext { shown_lines: usize, total_lines: usize, diff --git a/src/components/contacts/contact_list.rs b/src/components/contacts/contact_list.rs index b240c9fdc..52684cd93 100644 --- a/src/components/contacts/contact_list.rs +++ b/src/components/contacts/contact_list.rs @@ -25,7 +25,7 @@ use melib::CardId; use std::cmp; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] enum ViewMode { List, View(ComponentId), diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index 1a647344c..47a6766d7 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -41,7 +41,7 @@ mod gpg; mod edit_attachments; use edit_attachments::*; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] enum Cursor { Headers, Body, @@ -227,7 +227,7 @@ impl Composer { ) .as_ref() .map(|v| v.iter().map(String::as_str).collect::>()) - .unwrap_or(vec![]); + .unwrap_or_default(); let subject = subject .as_ref() .strip_prefixes_from_list(if prefix_list.is_empty() { @@ -242,7 +242,7 @@ impl Composer { if !subject.starts_with(prefix) { format!("{prefix} {subject}", prefix = prefix, subject = subject) } else { - subject.to_string() + subject } }; ret.draft.set_header("Subject", subject); @@ -1114,7 +1114,7 @@ impl Component for Composer { Some(Box::new(move |id: ComponentId, results: &[char]| { Some(UIEvent::FinishedUIDialog( id, - Box::new(results.get(0).cloned().unwrap_or('c')), + Box::new(results.first().cloned().unwrap_or('c')), )) })), context, @@ -2044,7 +2044,7 @@ impl Component for Composer { Some(Box::new(move |id: ComponentId, results: &[char]| { Some(UIEvent::FinishedUIDialog( id, - Box::new(results.get(0).copied().unwrap_or('n')), + Box::new(results.first().copied().unwrap_or('n')), )) })), context, @@ -2093,7 +2093,7 @@ impl Component for Composer { Some(Box::new(move |id: ComponentId, results: &[char]| { Some(UIEvent::FinishedUIDialog( id, - Box::new(results.get(0).copied().unwrap_or('n')), + Box::new(results.first().copied().unwrap_or('n')), )) })), context, diff --git a/src/components/mail/compose/edit_attachments.rs b/src/components/mail/compose/edit_attachments.rs index 54a625eab..9e1a61a87 100644 --- a/src/components/mail/compose/edit_attachments.rs +++ b/src/components/mail/compose/edit_attachments.rs @@ -21,7 +21,7 @@ use super::*; -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum EditAttachmentCursor { AttachmentNo(usize), Buttons, diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 0b0f1d89b..d6798e0ca 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -68,7 +68,7 @@ pub enum Focus { EntryFullscreen, } -#[derive(Debug, Copy, PartialEq, Clone)] +#[derive(Debug, Copy, PartialEq, Eq, Clone)] pub enum Modifier { SymmetricDifference, Union, @@ -594,19 +594,19 @@ impl ListingComponent { } } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] enum ListingFocus { Menu, Mailbox, } -#[derive(PartialEq, Copy, Clone, Debug)] +#[derive(PartialEq, Eq, Copy, Clone, Debug)] enum MenuEntryCursor { Status, Mailbox(usize), } -#[derive(PartialEq, Copy, Clone, Debug)] +#[derive(PartialEq, Eq, Copy, Clone, Debug)] enum ShowMenuScrollbar { Never, True, diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index a81be52ce..3e3df96ea 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -697,7 +697,7 @@ impl ConversationsListing { if !acc.is_empty() { acc.push_str(", "); } - acc.push_str(&s); + acc.push_str(s); acc }) } else { diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index 396e272ac..dd9b11147 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -23,6 +23,7 @@ use super::*; use crate::components::PageMovement; use std::cmp; use std::convert::TryInto; +use std::fmt::Write; macro_rules! row_attr { ($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{ @@ -883,7 +884,7 @@ impl ThreadListing { }); */ if show_subject { - s.push_str(&format!("{:.85}", envelope.subject())); + let _ = write!(s, "{:.85}", envelope.subject()); } s } diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index f46776293..e45fdca93 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -27,6 +27,7 @@ use melib::list_management; use melib::parser::BytesExt; use smallvec::SmallVec; use std::collections::HashSet; +use std::fmt::Write as _; use std::io::Write; use std::convert::TryFrom; @@ -44,7 +45,7 @@ pub use self::envelope::*; use linkify::LinkFinder; use xdg_utils::query_default_app; -#[derive(PartialEq, Copy, Clone, Debug)] +#[derive(PartialEq, Eq, Copy, Clone, Debug)] enum Source { Decoded, Raw, @@ -530,7 +531,7 @@ impl MailView { error, } => { if show_comments { - acc.push_str(&format!("Failed to verify signature: {}.\n\n", error)); + let _ = writeln!(acc, "Failed to verify signature: {}.\n", error); } acc.push_str(&self.attachment_displays_to_text( display, @@ -559,7 +560,7 @@ impl MailView { } EncryptedPending { .. } => acc.push_str("Waiting for decryption result."), EncryptedFailed { inner: _, error } => { - acc.push_str(&format!("Decryption failed: {}.", &error)) + let _ = write!(acc, "Decryption failed: {}.", &error); } EncryptedSuccess { inner: _, diff --git a/src/components/mail/view/envelope.rs b/src/components/mail/view/envelope.rs index 2f310558a..9b8109351 100644 --- a/src/components/mail/view/envelope.rs +++ b/src/components/mail/view/envelope.rs @@ -25,7 +25,7 @@ use std::process::{Command, Stdio}; use xdg_utils::query_default_app; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] enum ViewMode { Normal, Url, @@ -134,7 +134,7 @@ impl EnvelopeView { .iter() .enumerate() .fold(t, |mut s, (idx, a)| { - s.push_str(&format!("[{}] {}\n\n", idx, a)); + let _ = writeln!(s, "[{}] {}\n", idx, a); s }); } @@ -161,7 +161,7 @@ impl EnvelopeView { .iter() .enumerate() .fold(t, |mut s, (idx, a)| { - s.push_str(&format!("[{}] {}\n\n", idx, a)); + let _ = writeln!(s, "[{}] {}\n", idx, a); s }); } diff --git a/src/components/mail/view/html.rs b/src/components/mail/view/html.rs index fe72a0402..ca9ec2800 100644 --- a/src/components/mail/view/html.rs +++ b/src/components/mail/view/html.rs @@ -105,7 +105,7 @@ impl HtmlView { .iter() .enumerate() .fold(display_text, |mut s, (idx, a)| { - s.push_str(&format!("[{}] {}\n\n\n", idx, a)); + let _ = writeln!(s, "[{}] {}\n\n", idx, a); s }); } diff --git a/src/components/notifications.rs b/src/components/notifications.rs index 9c0fff009..a28d99c96 100644 --- a/src/components/notifications.rs +++ b/src/components/notifications.rs @@ -151,13 +151,14 @@ mod dbus { '"' => ret.push_str("""), _ => { let i = c as u32; - if (0x1 <= i && i <= 0x8) - || (0xb <= i && i <= 0xc) - || (0xe <= i && i <= 0x1f) - || (0x7f <= i && i <= 0x84) - || (0x86 <= i && i <= 0x9f) + if (0x1..=0x8).contains(&i) + || (0xb..=0xc).contains(&i) + || (0xe..=0x1f).contains(&i) + || (0x7f..=0x84).contains(&i) + || (0x86..=0x9f).contains(&i) { - ret.push_str(&format!("&#{:x}%{:x};", i, i)); + use std::fmt::Write; + let _ = write!(ret, "&#{:x}%{:x};", i, i); } else { ret.push(c); } diff --git a/src/components/utilities.rs b/src/components/utilities.rs index b8a988808..d1ad816aa 100644 --- a/src/components/utilities.rs +++ b/src/components/utilities.rs @@ -1547,7 +1547,7 @@ impl Component for Tabbed { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct RawBuffer { pub buf: CellBuffer, title: Option, diff --git a/src/components/utilities/dialogs.rs b/src/components/utilities/dialogs.rs index 1cdac8c19..270444cc5 100644 --- a/src/components/utilities/dialogs.rs +++ b/src/components/utilities/dialogs.rs @@ -27,7 +27,7 @@ const OK_LENGTH: usize = "OK".len(); const CANCEL_OFFSET: usize = "OK ".len(); const CANCEL_LENGTH: usize = "Cancel".len(); -#[derive(Debug, Copy, PartialEq, Clone)] +#[derive(Debug, Copy, PartialEq, Eq, Clone)] enum SelectorCursor { Unfocused, /// Cursor is at an entry diff --git a/src/components/utilities/widgets.rs b/src/components/utilities/widgets.rs index 9400a4e2f..682d6b126 100644 --- a/src/components/utilities/widgets.rs +++ b/src/components/utilities/widgets.rs @@ -26,7 +26,7 @@ use std::time::Duration; type AutoCompleteFn = Box Vec + Send + Sync>; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] enum FormFocus { Fields, Buttons, @@ -390,7 +390,7 @@ impl fmt::Display for Field { } } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum FormButtonActions { Accept, Reset, @@ -870,7 +870,7 @@ where } } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct AutoCompleteEntry { pub entry: String, pub description: String, @@ -911,7 +911,7 @@ impl From<(String, String)> for AutoCompleteEntry { } } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct AutoComplete { entries: Vec, content: CellBuffer, diff --git a/src/conf.rs b/src/conf.rs index eb205ef6e..fc3412a1c 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -573,7 +573,7 @@ impl Settings { } } -#[derive(Copy, Debug, Clone, Hash, PartialEq)] +#[derive(Copy, Debug, Clone, Hash, PartialEq, Eq)] pub enum IndexStyle { Plain, Threaded, @@ -703,7 +703,7 @@ impl Serialize for IndexStyle { } } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum SearchBackend { None, Auto, diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 977ce8da1..5c859a25a 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -1204,11 +1204,11 @@ impl Account { ), melib::INFO, ); - return Err(MeliError::new(format!( + Err(MeliError::new(format!( "Message was stored in {} so that you can restore it manually.", file.path.display() )) - .set_summary("Could not save in any mailbox")); + .set_summary("Could not save in any mailbox")) } } diff --git a/src/conf/themes.rs b/src/conf/themes.rs index 15bd9e050..a262286ab 100644 --- a/src/conf/themes.rs +++ b/src/conf/themes.rs @@ -36,6 +36,7 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use smallvec::SmallVec; use std::borrow::Cow; use std::collections::HashSet; +use std::fmt::Write; #[inline(always)] pub fn value(context: &Context, key: &'static str) -> ThemeAttribute { @@ -1240,26 +1241,28 @@ impl Themes { t => self.other_themes.get(t).unwrap_or(&self.dark), }; let mut ret = String::new(); - ret.push_str(&format!("[terminal.themes.{}]\n", key)); + let _ = writeln!(ret, "[terminal.themes.{}]", key); if unlink { for k in theme.keys() { - ret.push_str(&format!( - "\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}\n", + let _ = writeln!( + ret, + "\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}", k, toml::to_string(&unlink_fg(theme, &ColorField::Fg, k)).unwrap(), toml::to_string(&unlink_bg(theme, &ColorField::Bg, k)).unwrap(), toml::to_string(&unlink_attrs(theme, k)).unwrap(), - )); + ); } } else { for k in theme.keys() { - ret.push_str(&format!( - "\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}\n", + let _ = writeln!( + ret, + "\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}", k, toml::to_string(&theme[k].fg).unwrap(), toml::to_string(&theme[k].bg).unwrap(), toml::to_string(&theme[k].attrs).unwrap(), - )); + ); } } ret diff --git a/src/plugins.rs b/src/plugins.rs index d2bf14bc4..c0bbdae04 100644 --- a/src/plugins.rs +++ b/src/plugins.rs @@ -36,7 +36,7 @@ pub use rpc::*; pub const BACKEND_FN: i8 = 0; pub const BACKEND_OP_FN: i8 = 1; -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum PluginKind { LongLived, Filter, diff --git a/src/terminal/color.rs b/src/terminal/color.rs index 2a94a588c..cc32ebc57 100644 --- a/src/terminal/color.rs +++ b/src/terminal/color.rs @@ -456,7 +456,7 @@ impl<'de> Deserialize<'de> for Color { #[test] fn test_color_de() { - #[derive(Debug, Deserialize, PartialEq)] + #[derive(Debug, Deserialize, PartialEq, Eq)] struct V { k: Color, } diff --git a/src/terminal/embed/grid.rs b/src/terminal/embed/grid.rs index 0eb90e184..8d924278f 100644 --- a/src/terminal/embed/grid.rs +++ b/src/terminal/embed/grid.rs @@ -179,7 +179,7 @@ impl EmbedTerminal { } } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] enum CodepointBuf { None, TwoCodepoints(u8), diff --git a/src/terminal/keys.rs b/src/terminal/keys.rs index bfc3ac2bc..10ba784e8 100644 --- a/src/terminal/keys.rs +++ b/src/terminal/keys.rs @@ -139,7 +139,7 @@ impl PartialEq for &Key { } } -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] /// Keep track of whether we're accepting normal user input or a pasted string. enum InputMode { Normal, @@ -359,7 +359,7 @@ impl Serialize for Key { #[test] fn test_key_serde() { - #[derive(Debug, Deserialize, PartialEq)] + #[derive(Debug, Deserialize, PartialEq, Eq)] struct V { k: Key, } diff --git a/src/terminal/position.rs b/src/terminal/position.rs index a7cad12b8..9c93a0b07 100644 --- a/src/terminal/position.rs +++ b/src/terminal/position.rs @@ -170,7 +170,7 @@ pub fn center_area(area: Area, (width, height): (usize, usize)) -> Area { ) } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Alignment { /// Stretch to fill all space if possible, center if no meaningful way to stretch. Fill, diff --git a/src/terminal/text_editing.rs b/src/terminal/text_editing.rs index 9a0fb9ae1..47b3889e8 100644 --- a/src/terminal/text_editing.rs +++ b/src/terminal/text_editing.rs @@ -21,7 +21,7 @@ use melib::text_processing::TextProcessing; -#[derive(Debug, Clone, Default, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct UText { content: String, cursor_pos: usize, diff --git a/src/types.rs b/src/types.rs index 3e545a25a..3cb2dfc4b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -169,7 +169,7 @@ impl From for UIEvent { } } -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum UIMode { Normal, Insert,