diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-18 21:13:58 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-18 21:14:14 +0300 |
commit | 24831b3c13c351418d990e9c8ea94bbece223d97 (patch) | |
tree | ee92edf8271af8e7f837bddff6037d2bb45451aa | |
parent | a51a164711bab2dc116d089fa494baf7013b2a98 (diff) |
Fix warnings, lints, and 2018 errors
42 files changed, 223 insertions, 267 deletions
diff --git a/debug_printer/Cargo.toml b/debug_printer/Cargo.toml index 795d069c..2bcd9fc2 100644 --- a/debug_printer/Cargo.toml +++ b/debug_printer/Cargo.toml @@ -3,6 +3,7 @@ name = "debug_printer" version = "0.0.1" #:version authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"] workspace = ".." +edition = "2018" [lib] name = "debugprinter" diff --git a/melib/Cargo.toml b/melib/Cargo.toml index e522490b..9f4f38d7 100644 --- a/melib/Cargo.toml +++ b/melib/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "melib" version = "0.0.1" #:version -edition = "2018" authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"] workspace = ".." +edition = "2018" [dependencies] bitflags = "1.0" diff --git a/melib/src/addressbook.rs b/melib/src/addressbook.rs index 8a79041b..72076be2 100644 --- a/melib/src/addressbook.rs +++ b/melib/src/addressbook.rs @@ -173,7 +173,7 @@ impl Card { self.extra_properties.insert(key.to_string(), value); } pub fn extra_property(&self, key: &str) -> Option<&str> { - self.extra_properties.get(key).map(|v| v.as_str()) + self.extra_properties.get(key).map(String::as_str) } } diff --git a/melib/src/backends/maildir.rs b/melib/src/backends/maildir.rs index 72bb3ffb..3adcce6f 100644 --- a/melib/src/backends/maildir.rs +++ b/melib/src/backends/maildir.rs @@ -168,9 +168,7 @@ impl<'a> BackendOp for MaildirOp { let hash_index = self.hash_index.clone(); let mut map = hash_index.lock().unwrap(); let map = map.entry(self.folder_hash).or_default(); - if let maildir_path = map.entry(old_hash).or_default() { - maildir_path.modified = Some(new_name.clone().into()); - } + map.entry(old_hash).or_default().modified = Some(new_name.clone()); Ok(()) } } @@ -247,11 +245,11 @@ impl BackendFolder for MaildirFolder { name: self.name.clone(), path: self.path.clone(), children: self.children.clone(), - parent: self.parent.clone(), + parent: self.parent, }) } fn parent(&self) -> Option<FolderHash> { - self.parent.clone() + self.parent } } diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index 7815ea5a..9d1b45ea 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -29,7 +29,8 @@ use crate::conf::AccountSettings; use crate::email::{Envelope, EnvelopeHash}; use crate::error::{MeliError, Result}; -use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; +extern crate notify; +use self::notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use std::time::Duration; use std::sync::mpsc::channel; @@ -166,7 +167,7 @@ fn move_to_cur(p: PathBuf) -> PathBuf { new.set_extension(":2,"); } debug!("moved to cur: {}", new.display()); - fs::rename(p, &new).unwrap(); + fs::rename(&p, &new).unwrap(); new } @@ -263,11 +264,6 @@ impl MailBackend for MaildirType { } else { /* Did we just miss a Create event? In any case, create * envelope. */ - - /* Drop the lock manually as add_path_to_index would deadlock - * */ - drop(index_lock); - drop(hash_indexes_lock); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, @@ -369,10 +365,6 @@ impl MailBackend for MaildirType { .unwrap() .to_path_buf(); debug!("filename = {:?}", file_name); - /* Drop the lock manually as add_path_to_index would deadlock - * */ - drop(index_lock); - drop(hash_indexes_lock); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, diff --git a/melib/src/collection.rs b/melib/src/collection.rs index 375050e6..3ae8c214 100644 --- a/melib/src/collection.rs +++ b/melib/src/collection.rs @@ -130,56 +130,50 @@ impl Collection { true } }); - let mut threads = Threads::new(&mut envelopes); + let mut new_threads = Threads::new(&mut envelopes); for (h, e) in envelopes { self.envelopes.insert(h, e); } - for (t_fh, t) in self.threads.iter_mut() { - if self.sent_folder.map(|f| f == folder_hash).unwrap_or(false) { - let mut ordered_hash_set = threads + let &mut Collection { + ref mut threads, + ref mut envelopes, + ref sent_folder, + .. + } = self; + for (t_fh, t) in threads.iter_mut() { + if sent_folder.map(|f| f == folder_hash).unwrap_or(false) { + let mut ordered_hash_set = new_threads .hash_set .iter() .cloned() .collect::<Vec<EnvelopeHash>>(); - unsafe { - /* FIXME NLL - * Sorting ordered_hash_set triggers a borrow which should not happen with NLL - * probably */ - let envelopes = &self.envelopes as *const FnvHashMap<EnvelopeHash, Envelope>; - ordered_hash_set.sort_by(|a, b| { - (*envelopes)[a] - .date() - .partial_cmp(&(*(envelopes))[b].date()) - .unwrap() - }); - } + ordered_hash_set.sort_by(|a, b| { + envelopes[a] + .date() + .partial_cmp(&envelopes[b].date()) + .unwrap() + }); for h in ordered_hash_set { - t.insert_reply(&mut self.envelopes, h); + t.insert_reply(envelopes, h); } continue; } - if self.sent_folder.map(|f| f == *t_fh).unwrap_or(false) { + if sent_folder.map(|f| f == *t_fh).unwrap_or(false) { let mut ordered_hash_set = t.hash_set.iter().cloned().collect::<Vec<EnvelopeHash>>(); - unsafe { - /* FIXME NLL - * Sorting ordered_hash_set triggers a borrow which should not happen with NLL - * probably */ - let envelopes = &self.envelopes as *const FnvHashMap<EnvelopeHash, Envelope>; - ordered_hash_set.sort_by(|a, b| { - (*envelopes)[a] - .date() - .partial_cmp(&(*(envelopes))[b].date()) - .unwrap() - }); - } + ordered_hash_set.sort_by(|a, b| { + envelopes[a] + .date() + .partial_cmp(&envelopes[b].date()) + .unwrap() + }); for h in ordered_hash_set { - threads.insert_reply(&mut self.envelopes, h); + new_threads.insert_reply(envelopes, h); } } } - self.threads.insert(folder_hash, threads); + threads.insert(folder_hash, new_threads); } pub fn update(&mut self, old_hash: EnvelopeHash, envelope: Envelope, folder_hash: FolderHash) { @@ -190,7 +184,8 @@ impl Collection { self.envelopes.insert(new_hash, envelope); if self.sent_folder.map(|f| f == folder_hash).unwrap_or(false) { for (_, t) in self.threads.iter_mut() { - t.update_envelope(old_hash, new_hash, &self.envelopes); + t.update_envelope(old_hash, new_hash, &self.envelopes) + .unwrap_or(()); } } { diff --git a/melib/src/email.rs b/melib/src/email.rs index af1171f7..367a8a22 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -30,7 +30,7 @@ mod attachment_types; pub mod attachments; pub use crate::attachments::*; pub mod parser; -use parser::BytesExt; +use crate::parser::BytesExt; use crate::backends::BackendOp; use crate::error::{MeliError, Result}; @@ -472,8 +472,7 @@ impl Envelope { let b = builder.build(); let subs = b.attachments(); - self.has_attachments = - subs.iter().fold(false, |acc, sub| acc || !sub.is_text()); + self.has_attachments = subs.iter().any(|sub| !sub.is_text()); } _ => {} } diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs index 95c9462c..3621f103 100644 --- a/melib/src/email/attachments.rs +++ b/melib/src/email/attachments.rs @@ -60,7 +60,7 @@ impl fmt::Debug for Attachment { { let mut text = Vec::with_capacity(4096); self.get_text_recursive(&mut text); - std::str::from_utf8(&text).map(|r| r.to_string()).unwrap_or_else(|e| format!("Unicode error {}", e)) + std::str::from_utf8(&text).map(std::string::ToString::to_string).unwrap_or_else(|e| format!("Unicode error {}", e)) } ) } @@ -346,7 +346,7 @@ impl Attachment { String::from_utf8_lossy(text.as_slice().trim()).into() } pub fn description(&self) -> Vec<String> { - self.attachments().iter().map(|a| a.text()).collect() + self.attachments().iter().map(Attachment::text).collect() } pub fn mime_type(&self) -> String { format!("{}", self.content_type).to_string() @@ -408,7 +408,7 @@ impl Attachment { return false; } } - return true; + true } ContentType::Multipart { kind: MultipartType::Signed, @@ -417,7 +417,7 @@ impl Attachment { } => subattachments .iter() .find(|s| s.content_type != ContentType::PGPSignature) - .map(|s| s.is_html()) + .map(Attachment::is_html) .unwrap_or(false), ContentType::Multipart { ref subattachments, .. @@ -468,11 +468,14 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment { type Filter<'a> = Box<FnMut(&'a Attachment, &mut Vec<u8>) -> () + 'a>; fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<u8> { - let ret = match a.content_type { + match a.content_type { ContentType::Unsupported { .. } => Vec::new(), ContentType::Text { .. } => decode_helper(a, filter), ContentType::PGPSignature => a.content_type.to_string().into_bytes(), - ContentType::MessageRfc822 => decode_rec(&decode_rfc822(&a.raw), None), + ContentType::MessageRfc822 => { + let temp = decode_rfc822(&a.raw); + decode_rec(&temp, None) + } ContentType::Multipart { ref kind, ref subattachments, @@ -497,8 +500,7 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> vec } }, - }; - ret + } } pub fn decode_rec<'a>(a: &'a Attachment, mut filter: Option<Filter<'a>>) -> Vec<u8> { diff --git a/melib/src/email/compose/mime.rs b/melib/src/email/compose/mime.rs index 5164cfd1..fa6b8517 100644 --- a/melib/src/email/compose/mime.rs +++ b/melib/src/email/compose/mime.rs @@ -2,7 +2,7 @@ use super::*; pub fn encode_header(value: &str) -> String { eprintln!("encoding \"{}\"", value); - let mut ret = String::with_capacity(5 / 3 * value.len()); + let mut ret = String::with_capacity(value.len()); for word in value.split_whitespace() { if word.is_ascii() { ret.push_str(word); diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index dc6410ee..cba49644 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -896,11 +896,11 @@ mod tests { } #[test] fn test_attachments() { - use std::io::Read; - let mut buffer: Vec<u8> = Vec::new(); //FIXME: add file return; /* + use std::io::Read; + let mut buffer: Vec<u8> = Vec::new(); let _ = std::fs::File::open("").unwrap().read_to_end(&mut buffer); let boundary = b"b1_4382d284f0c601a737bb32aaeda53160"; let (_, body) = match mail(&buffer).to_full_result() { diff --git a/melib/src/grapheme_clusters.rs b/melib/src/grapheme_clusters.rs index 80887ca6..8553c9e4 100644 --- a/melib/src/grapheme_clusters.rs +++ b/melib/src/grapheme_clusters.rs @@ -9,7 +9,8 @@ */ use super::*; -use unicode_segmentation::UnicodeSegmentation; +extern crate unicode_segmentation; +use self::unicode_segmentation::UnicodeSegmentation; pub trait Graphemes: UnicodeSegmentation + CodePointsIter { fn split_graphemes<'a>(&'a self) -> Vec<&'a str> { diff --git a/melib/src/lib.rs b/melib/src/lib.rs index b05dc4ff..9edf2838 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -30,7 +30,7 @@ pub mod dbg { "[{:?}] {}:{}_{}: ", std::thread::current() .name() - .map(|v| v.to_string()) + .map(std::string::ToString::to_string) .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), file!(), line!(), @@ -48,7 +48,7 @@ pub mod dbg { "[{:?}] {}:{}_{}: ", std::thread::current() .name() - .map(|v| v.to_string()) + .map(std::string::ToString::to_string) .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), file!(), line!(), @@ -65,7 +65,7 @@ pub mod dbg { "[{:?}] {}:{}_{}: ", std::thread::current() .name() - .map(|v| v.to_string()) + .map(std::string::ToString::to_string) .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), file!(), line!(), @@ -88,7 +88,7 @@ pub mod grapheme_clusters; pub mod mailbox; pub mod thread; pub use crate::email::*; -pub use thread::*; +pub use crate::thread::*; mod wcwidth; pub use self::grapheme_clusters::*; pub use self::wcwidth::*; @@ -112,11 +112,11 @@ extern crate bitflags; extern crate fnv; extern crate uuid; -pub use conf::*; -pub use mailbox::*; +pub use crate::conf::*; +pub use crate::mailbox::*; -pub use backends::{Backends, RefreshEvent, RefreshEventConsumer}; -pub use email::{Envelope, Flag}; -pub use error::{MeliError, Result}; +pub use crate::backends::{Backends, RefreshEvent, RefreshEventConsumer}; +pub use crate::email::{Envelope, Flag}; +pub use crate::error::{MeliError, Result}; -pub use addressbook::*; +pub use crate::addressbook::*; diff --git a/melib/src/structs.rs b/melib/src/structs.rs index e725f209..3111bfc6 100644 --- a/melib/src/structs.rs +++ b/melib/src/structs.rs @@ -1,7 +1,7 @@ use std::iter::Extend; use std::ops::Index; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct StackVec<T: Default + Copy + std::fmt::Debug> { len: usize, array: [T; 32], @@ -42,7 +42,7 @@ impl<T: Default + Copy + std::fmt::Debug> StackVec<T> { self.heap_vec.pop() } else { let ret = self.array[self.len - 1]; - self.len = self.len - 1; + self.len -= 1; Some(ret) } } diff --git a/melib/src/thread.rs b/melib/src/thread.rs index 31b4403b..8934fadc 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -48,6 +48,7 @@ use std::mem; use std::ops::Index; use std::result::Result as StdResult; use std::str::FromStr; +use std::string::ToString; type Envelopes = FnvHashMap<EnvelopeHash, Envelope>; @@ -82,9 +83,12 @@ fn rec_change_root_parent( idx: ThreadHash, new_root: ThreadHash, ) { - let entry = b.entry(idx).or_default(); - entry.thread_group = new_root; - if let Some(p) = entry.parent { + let parent = { + let entry = b.entry(idx).or_default(); + entry.thread_group = new_root; + entry.parent + }; + if let Some(p) = parent { rec_change_children(b, p, new_root); rec_change_root_parent(b, p, new_root); } @@ -109,8 +113,8 @@ fn rec_change_children( macro_rules! remove_from_parent { ($buf:expr, $idx:expr) => {{ let mut parent: Option<ThreadHash> = None; - let entry = $buf.entry($idx).or_default(); - if let Some(p) = entry.parent { + let entry_parent = $buf.entry($idx).or_default().parent; + if let Some(p) = entry_parent { parent = Some(p); if let Some(pos) = $buf[&p].children.iter().position(|c| *c == $idx) { $buf.entry(p).and_modify(|e| { @@ -964,14 +968,14 @@ impl Threads { .get( envelopes[&env_hash] .in_reply_to() - .map(|mgid| mgid.raw()) + .map(crate::email::StrBuild::raw) .unwrap_or(&[]), ) - .map(|h| *h); + .cloned(); if let Some(id) = self .message_ids .get(envelopes[&env_hash].message_id().raw()) - .map(|h| *h) + .cloned() { self.thread_nodes.entry(id).and_modify(|n| { n.message = Some(env_hash); @@ -1069,11 +1073,8 @@ impl Threads { } } let no_parent: bool = if let Some(node) = self.thread_nodes.get(&node_idx) { - match (node.parent, node.message, node.children.len()) { - (None, None, 0) => { - return; - } - _ => {} + if let (None, None, 0) = (node.parent, node.message, node.children.len()) { + return; } node.parent.is_none() } else { @@ -1085,10 +1086,10 @@ impl Threads { if no_parent { let tree = self.tree.get_mut(); - if let Some(tree) = tree.iter_mut().find(|t| t.id == id) { - *tree = ThreadTree::new(id); + if let Some(pos) = tree.iter().position(|t| t.id == id) { + tree[pos] = ThreadTree::new(id); node_build( - tree, + &mut tree[pos], id, *(self.sort.borrow()), &mut self.thread_nodes, @@ -1481,7 +1482,7 @@ impl Threads { ref_ptr = parent_id; continue; } */ - if !self.thread_nodes[&ref_ptr].parent.is_none() { + if self.thread_nodes[&ref_ptr].parent.is_some() { if self.thread_nodes[&parent_id].parent == Some(ref_ptr) { eprintln!("ALARM"); remove_from_parent!(&mut self.thread_nodes, parent_id); @@ -1506,12 +1507,9 @@ impl Threads { while i < tree.len() { // Evaluate if useless let node = &self.thread_nodes[&tree[i].id]; - match (node.parent, node.message, node.children.len()) { - (None, None, 0) => { - tree.remove(i); - continue; - } - _ => {} + if let (None, None, 0) = (node.parent, node.message, node.children.len()) { + tree.remove(i); + continue; } i += 1; } @@ -1570,14 +1568,9 @@ fn node_build( } } } - } else { - if let Some(node) = thread_nodes.get(&idx) { - match (node.parent, node.message, node.children.len()) { - (None, None, 0) => { - return; - } - _ => {} - } + } else if let Some(node) = thread_nodes.get(&idx) { + if let (None, None, 0) = (node.parent, node.message, node.children.len()) { + return; } } @@ -1648,9 +1641,9 @@ fn print_threadnodes( "\t".repeat(level), node_hash, "\t".repeat(level), - nodes[&node_hash].message().as_ref().map(|m| format!("{} - {}\n{}\t\t{}", envelopes[m].message_id_display(), envelopes[m].subject(), "\t".repeat(level), envelopes[m].references().iter().map(|r| r.to_string()).collect::<Vec<String>>().join(", "))).unwrap_or_else(|| "None".to_string()), + nodes[&node_hash].message().as_ref().map(|m| format!("{} - {}\n{}\t\t{}", envelopes[m].message_id_display(), envelopes[m].subject(), "\t".repeat(level), envelopes[m].references().iter().map(ToString::to_string).collect::<Vec<String>>().join(", "))).unwrap_or_else(|| "None".to_string()), "\t".repeat(level), - nodes[&node_hash].parent().as_ref().map(|p| p.to_string()).unwrap_or_else(|| "None".to_string()), + nodes[&node_hash].parent().as_ref().map(ToString::to_string).unwrap_or_else(|| "None".to_string()), "\t".repeat(level), nodes[&node_hash].thread_group, "\t".repeat(level), diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 7f45d594..d6afbc05 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -3,6 +3,7 @@ name = "testing" version = "0.0.1" #:version authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"] workspace = ".." +edition = "2018" [[bin]] name = "emailparse" diff --git a/ui/Cargo.toml b/ui/Cargo.toml index 8cc0d698..920589e5 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -3,6 +3,7 @@ name = "ui" version = "0.0.1" #:version authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"] workspace = ".." +edition = "2018" [dependencies] xdg = "2.1.0" # >:c diff --git a/ui/src/components.rs b/ui/src/components.rs index b27cd5eb..6e753ed6 100644 --- a/ui/src/components.rs +++ b/ui/src/components.rs @@ -28,7 +28,7 @@ See the `Component` Trait for more details. use super::*; pub mod mail; -pub use mail::*; +pub use crate::mail::*; pub mod notifications; @@ -39,7 +39,7 @@ pub mod utilities; pub use self::utilities::*; pub mod contacts; -pub use contacts::*; +pub use crate::contacts::*; use std::fmt; use std::fmt::{Debug, Display}; diff --git a/ui/src/components/contacts.rs b/ui/src/components/contacts.rs index 3f844b85..e3fa8b84 100644 --- a/ui/src/components/contacts.rs +++ b/ui/src/components/contacts.rs @@ -139,7 +139,7 @@ impl Component for ContactManager { match self.form.buttons_result() { None => {} Some(true) => { - let mut fields = std::mem::replace(&mut self.form, FormWidget::default()) + let fields = std::mem::replace(&mut self.form, FormWidget::default()) .collect() .unwrap(); let fields: FnvHashMap<String, String> = fields diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs index e706982c..4fdf4c93 100644 --- a/ui/src/components/mail.rs +++ b/ui/src/components/mail.rs @@ -27,9 +27,9 @@ use melib::backends::FolderHash; use melib::thread::ThreadHash; pub mod listing; -pub use listing::*; +pub use crate::listing::*; pub mod view; -pub use view::*; +pub use crate::view::*; mod compose; pub use self::compose::*; diff --git a/ui/src/components/mail/co |