Fix clippy lints for `meli` crate

pull/150/head
Manos Pitsidianakis 2022-09-11 15:19:40 +03:00
parent 388d4e35d6
commit 94bd84b45d
25 changed files with 60 additions and 54 deletions

View File

@ -39,7 +39,7 @@ fn main() {
{ {
use flate2::Compression; use flate2::Compression;
use flate2::GzBuilder; 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::env;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;

View File

@ -66,7 +66,7 @@ pub enum PageMovement {
End, End,
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScrollContext { pub struct ScrollContext {
shown_lines: usize, shown_lines: usize,
total_lines: usize, total_lines: usize,

View File

@ -25,7 +25,7 @@ use melib::CardId;
use std::cmp; use std::cmp;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
enum ViewMode { enum ViewMode {
List, List,
View(ComponentId), View(ComponentId),

View File

@ -41,7 +41,7 @@ mod gpg;
mod edit_attachments; mod edit_attachments;
use edit_attachments::*; use edit_attachments::*;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
enum Cursor { enum Cursor {
Headers, Headers,
Body, Body,
@ -227,7 +227,7 @@ impl Composer {
) )
.as_ref() .as_ref()
.map(|v| v.iter().map(String::as_str).collect::<Vec<&str>>()) .map(|v| v.iter().map(String::as_str).collect::<Vec<&str>>())
.unwrap_or(vec![]); .unwrap_or_default();
let subject = subject let subject = subject
.as_ref() .as_ref()
.strip_prefixes_from_list(if prefix_list.is_empty() { .strip_prefixes_from_list(if prefix_list.is_empty() {
@ -242,7 +242,7 @@ impl Composer {
if !subject.starts_with(prefix) { if !subject.starts_with(prefix) {
format!("{prefix} {subject}", prefix = prefix, subject = subject) format!("{prefix} {subject}", prefix = prefix, subject = subject)
} else { } else {
subject.to_string() subject
} }
}; };
ret.draft.set_header("Subject", subject); ret.draft.set_header("Subject", subject);
@ -1114,7 +1114,7 @@ impl Component for Composer {
Some(Box::new(move |id: ComponentId, results: &[char]| { Some(Box::new(move |id: ComponentId, results: &[char]| {
Some(UIEvent::FinishedUIDialog( Some(UIEvent::FinishedUIDialog(
id, id,
Box::new(results.get(0).cloned().unwrap_or('c')), Box::new(results.first().cloned().unwrap_or('c')),
)) ))
})), })),
context, context,
@ -2044,7 +2044,7 @@ impl Component for Composer {
Some(Box::new(move |id: ComponentId, results: &[char]| { Some(Box::new(move |id: ComponentId, results: &[char]| {
Some(UIEvent::FinishedUIDialog( Some(UIEvent::FinishedUIDialog(
id, id,
Box::new(results.get(0).copied().unwrap_or('n')), Box::new(results.first().copied().unwrap_or('n')),
)) ))
})), })),
context, context,
@ -2093,7 +2093,7 @@ impl Component for Composer {
Some(Box::new(move |id: ComponentId, results: &[char]| { Some(Box::new(move |id: ComponentId, results: &[char]| {
Some(UIEvent::FinishedUIDialog( Some(UIEvent::FinishedUIDialog(
id, id,
Box::new(results.get(0).copied().unwrap_or('n')), Box::new(results.first().copied().unwrap_or('n')),
)) ))
})), })),
context, context,

View File

@ -21,7 +21,7 @@
use super::*; use super::*;
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum EditAttachmentCursor { pub enum EditAttachmentCursor {
AttachmentNo(usize), AttachmentNo(usize),
Buttons, Buttons,

View File

@ -68,7 +68,7 @@ pub enum Focus {
EntryFullscreen, EntryFullscreen,
} }
#[derive(Debug, Copy, PartialEq, Clone)] #[derive(Debug, Copy, PartialEq, Eq, Clone)]
pub enum Modifier { pub enum Modifier {
SymmetricDifference, SymmetricDifference,
Union, Union,
@ -594,19 +594,19 @@ impl ListingComponent {
} }
} }
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
enum ListingFocus { enum ListingFocus {
Menu, Menu,
Mailbox, Mailbox,
} }
#[derive(PartialEq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
enum MenuEntryCursor { enum MenuEntryCursor {
Status, Status,
Mailbox(usize), Mailbox(usize),
} }
#[derive(PartialEq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
enum ShowMenuScrollbar { enum ShowMenuScrollbar {
Never, Never,
True, True,

View File

@ -697,7 +697,7 @@ impl ConversationsListing {
if !acc.is_empty() { if !acc.is_empty() {
acc.push_str(", "); acc.push_str(", ");
} }
acc.push_str(&s); acc.push_str(s);
acc acc
}) })
} else { } else {

View File

@ -23,6 +23,7 @@ use super::*;
use crate::components::PageMovement; use crate::components::PageMovement;
use std::cmp; use std::cmp;
use std::convert::TryInto; use std::convert::TryInto;
use std::fmt::Write;
macro_rules! row_attr { macro_rules! row_attr {
($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{ ($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{
@ -883,7 +884,7 @@ impl ThreadListing {
}); });
*/ */
if show_subject { if show_subject {
s.push_str(&format!("{:.85}", envelope.subject())); let _ = write!(s, "{:.85}", envelope.subject());
} }
s s
} }

View File

@ -27,6 +27,7 @@ use melib::list_management;
use melib::parser::BytesExt; use melib::parser::BytesExt;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Write as _;
use std::io::Write; use std::io::Write;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -44,7 +45,7 @@ pub use self::envelope::*;
use linkify::LinkFinder; use linkify::LinkFinder;
use xdg_utils::query_default_app; use xdg_utils::query_default_app;
#[derive(PartialEq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
enum Source { enum Source {
Decoded, Decoded,
Raw, Raw,
@ -530,7 +531,7 @@ impl MailView {
error, error,
} => { } => {
if show_comments { 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( acc.push_str(&self.attachment_displays_to_text(
display, display,
@ -559,7 +560,7 @@ impl MailView {
} }
EncryptedPending { .. } => acc.push_str("Waiting for decryption result."), EncryptedPending { .. } => acc.push_str("Waiting for decryption result."),
EncryptedFailed { inner: _, error } => { EncryptedFailed { inner: _, error } => {
acc.push_str(&format!("Decryption failed: {}.", &error)) let _ = write!(acc, "Decryption failed: {}.", &error);
} }
EncryptedSuccess { EncryptedSuccess {
inner: _, inner: _,

View File

@ -25,7 +25,7 @@ use std::process::{Command, Stdio};
use xdg_utils::query_default_app; use xdg_utils::query_default_app;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
enum ViewMode { enum ViewMode {
Normal, Normal,
Url, Url,
@ -134,7 +134,7 @@ impl EnvelopeView {
.iter() .iter()
.enumerate() .enumerate()
.fold(t, |mut s, (idx, a)| { .fold(t, |mut s, (idx, a)| {
s.push_str(&format!("[{}] {}\n\n", idx, a)); let _ = writeln!(s, "[{}] {}\n", idx, a);
s s
}); });
} }
@ -161,7 +161,7 @@ impl EnvelopeView {
.iter() .iter()
.enumerate() .enumerate()
.fold(t, |mut s, (idx, a)| { .fold(t, |mut s, (idx, a)| {
s.push_str(&format!("[{}] {}\n\n", idx, a)); let _ = writeln!(s, "[{}] {}\n", idx, a);
s s
}); });
} }

View File

@ -105,7 +105,7 @@ impl HtmlView {
.iter() .iter()
.enumerate() .enumerate()
.fold(display_text, |mut s, (idx, a)| { .fold(display_text, |mut s, (idx, a)| {
s.push_str(&format!("[{}] {}\n\n\n", idx, a)); let _ = writeln!(s, "[{}] {}\n\n", idx, a);
s s
}); });
} }

View File

@ -151,13 +151,14 @@ mod dbus {
'"' => ret.push_str("&quot;"), '"' => ret.push_str("&quot;"),
_ => { _ => {
let i = c as u32; let i = c as u32;
if (0x1 <= i && i <= 0x8) if (0x1..=0x8).contains(&i)
|| (0xb <= i && i <= 0xc) || (0xb..=0xc).contains(&i)
|| (0xe <= i && i <= 0x1f) || (0xe..=0x1f).contains(&i)
|| (0x7f <= i && i <= 0x84) || (0x7f..=0x84).contains(&i)
|| (0x86 <= i && i <= 0x9f) || (0x86..=0x9f).contains(&i)
{ {
ret.push_str(&format!("&#{:x}%{:x};", i, i)); use std::fmt::Write;
let _ = write!(ret, "&#{:x}%{:x};", i, i);
} else { } else {
ret.push(c); ret.push(c);
} }

View File

@ -1547,7 +1547,7 @@ impl Component for Tabbed {
} }
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawBuffer { pub struct RawBuffer {
pub buf: CellBuffer, pub buf: CellBuffer,
title: Option<String>, title: Option<String>,

View File

@ -27,7 +27,7 @@ const OK_LENGTH: usize = "OK".len();
const CANCEL_OFFSET: usize = "OK ".len(); const CANCEL_OFFSET: usize = "OK ".len();
const CANCEL_LENGTH: usize = "Cancel".len(); const CANCEL_LENGTH: usize = "Cancel".len();
#[derive(Debug, Copy, PartialEq, Clone)] #[derive(Debug, Copy, PartialEq, Eq, Clone)]
enum SelectorCursor { enum SelectorCursor {
Unfocused, Unfocused,
/// Cursor is at an entry /// Cursor is at an entry

View File

@ -26,7 +26,7 @@ use std::time::Duration;
type AutoCompleteFn = Box<dyn Fn(&Context, &str) -> Vec<AutoCompleteEntry> + Send + Sync>; type AutoCompleteFn = Box<dyn Fn(&Context, &str) -> Vec<AutoCompleteEntry> + Send + Sync>;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
enum FormFocus { enum FormFocus {
Fields, Fields,
Buttons, Buttons,
@ -390,7 +390,7 @@ impl fmt::Display for Field {
} }
} }
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum FormButtonActions { pub enum FormButtonActions {
Accept, Accept,
Reset, Reset,
@ -870,7 +870,7 @@ where
} }
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct AutoCompleteEntry { pub struct AutoCompleteEntry {
pub entry: String, pub entry: String,
pub description: 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 { pub struct AutoComplete {
entries: Vec<AutoCompleteEntry>, entries: Vec<AutoCompleteEntry>,
content: CellBuffer, content: CellBuffer,

View File

@ -573,7 +573,7 @@ impl Settings {
} }
} }
#[derive(Copy, Debug, Clone, Hash, PartialEq)] #[derive(Copy, Debug, Clone, Hash, PartialEq, Eq)]
pub enum IndexStyle { pub enum IndexStyle {
Plain, Plain,
Threaded, Threaded,
@ -703,7 +703,7 @@ impl Serialize for IndexStyle {
} }
} }
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SearchBackend { pub enum SearchBackend {
None, None,
Auto, Auto,

View File

@ -1204,11 +1204,11 @@ impl Account {
), ),
melib::INFO, melib::INFO,
); );
return Err(MeliError::new(format!( Err(MeliError::new(format!(
"Message was stored in {} so that you can restore it manually.", "Message was stored in {} so that you can restore it manually.",
file.path.display() file.path.display()
)) ))
.set_summary("Could not save in any mailbox")); .set_summary("Could not save in any mailbox"))
} }
} }

View File

@ -36,6 +36,7 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Write;
#[inline(always)] #[inline(always)]
pub fn value(context: &Context, key: &'static str) -> ThemeAttribute { 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), t => self.other_themes.get(t).unwrap_or(&self.dark),
}; };
let mut ret = String::new(); let mut ret = String::new();
ret.push_str(&format!("[terminal.themes.{}]\n", key)); let _ = writeln!(ret, "[terminal.themes.{}]", key);
if unlink { if unlink {
for k in theme.keys() { for k in theme.keys() {
ret.push_str(&format!( let _ = writeln!(
"\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}\n", ret,
"\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}",
k, k,
toml::to_string(&unlink_fg(theme, &ColorField::Fg, k)).unwrap(), toml::to_string(&unlink_fg(theme, &ColorField::Fg, k)).unwrap(),
toml::to_string(&unlink_bg(theme, &ColorField::Bg, k)).unwrap(), toml::to_string(&unlink_bg(theme, &ColorField::Bg, k)).unwrap(),
toml::to_string(&unlink_attrs(theme, k)).unwrap(), toml::to_string(&unlink_attrs(theme, k)).unwrap(),
)); );
} }
} else { } else {
for k in theme.keys() { for k in theme.keys() {
ret.push_str(&format!( let _ = writeln!(
"\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}\n", ret,
"\"{}\" = {{ fg = {}, bg = {}, attrs = {} }}",
k, k,
toml::to_string(&theme[k].fg).unwrap(), toml::to_string(&theme[k].fg).unwrap(),
toml::to_string(&theme[k].bg).unwrap(), toml::to_string(&theme[k].bg).unwrap(),
toml::to_string(&theme[k].attrs).unwrap(), toml::to_string(&theme[k].attrs).unwrap(),
)); );
} }
} }
ret ret

View File

@ -36,7 +36,7 @@ pub use rpc::*;
pub const BACKEND_FN: i8 = 0; pub const BACKEND_FN: i8 = 0;
pub const BACKEND_OP_FN: i8 = 1; 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 { pub enum PluginKind {
LongLived, LongLived,
Filter, Filter,

View File

@ -456,7 +456,7 @@ impl<'de> Deserialize<'de> for Color {
#[test] #[test]
fn test_color_de() { fn test_color_de() {
#[derive(Debug, Deserialize, PartialEq)] #[derive(Debug, Deserialize, PartialEq, Eq)]
struct V { struct V {
k: Color, k: Color,
} }

View File

@ -179,7 +179,7 @@ impl EmbedTerminal {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
enum CodepointBuf { enum CodepointBuf {
None, None,
TwoCodepoints(u8), TwoCodepoints(u8),

View File

@ -139,7 +139,7 @@ impl PartialEq<Key> for &Key {
} }
} }
#[derive(PartialEq)] #[derive(PartialEq, Eq)]
/// Keep track of whether we're accepting normal user input or a pasted string. /// Keep track of whether we're accepting normal user input or a pasted string.
enum InputMode { enum InputMode {
Normal, Normal,
@ -359,7 +359,7 @@ impl Serialize for Key {
#[test] #[test]
fn test_key_serde() { fn test_key_serde() {
#[derive(Debug, Deserialize, PartialEq)] #[derive(Debug, Deserialize, PartialEq, Eq)]
struct V { struct V {
k: Key, k: Key,
} }

View File

@ -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 { pub enum Alignment {
/// Stretch to fill all space if possible, center if no meaningful way to stretch. /// Stretch to fill all space if possible, center if no meaningful way to stretch.
Fill, Fill,

View File

@ -21,7 +21,7 @@
use melib::text_processing::TextProcessing; use melib::text_processing::TextProcessing;
#[derive(Debug, Clone, Default, PartialEq)] #[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct UText { pub struct UText {
content: String, content: String,
cursor_pos: usize, cursor_pos: usize,

View File

@ -169,7 +169,7 @@ impl From<RefreshEvent> for UIEvent {
} }
} }
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum UIMode { pub enum UIMode {
Normal, Normal,
Insert, Insert,