Fix clippy warnings (#3726)

This commit is contained in:
Hocuri
2022-11-03 16:44:35 +01:00
committed by GitHub
parent 7b66eb8b9c
commit f4ee86282e
13 changed files with 30 additions and 23 deletions

View File

@@ -554,7 +554,11 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
sql::housekeeping(&context).await.ok_or_log(&context); sql::housekeeping(&context).await.ok_or_log(&context);
} }
"listchats" | "listarchived" | "chats" => { "listchats" | "listarchived" | "chats" => {
let listflags = if arg0 == "listarchived" { 0x01 } else { 0 }; let listflags = if arg0 == "listarchived" {
DC_GCL_ARCHIVED_ONLY
} else {
0
};
let time_start = std::time::SystemTime::now(); let time_start = std::time::SystemTime::now();
let chatlist = Chatlist::try_load( let chatlist = Chatlist::try_load(
&context, &context,

View File

@@ -446,7 +446,7 @@ async fn handle_cmd(
} }
println!("{}", qr); println!("{}", qr);
let output = Command::new("qrencode") let output = Command::new("qrencode")
.args(&["-t", "ansiutf8", qr.as_str(), "-o", "-"]) .args(["-t", "ansiutf8", qr.as_str(), "-o", "-"])
.output() .output()
.expect("failed to execute process"); .expect("failed to execute process");
io::stdout().write_all(&output.stdout).unwrap(); io::stdout().write_all(&output.stdout).unwrap();

View File

@@ -2439,7 +2439,7 @@ pub async fn get_chat_media(
AND hidden=0 AND hidden=0
ORDER BY timestamp, id;", ORDER BY timestamp, id;",
paramsv![ paramsv![
if chat_id.is_none() { 1i32 } else { 0i32 }, chat_id.is_none(),
chat_id.unwrap_or_else(|| ChatId::new(0)), chat_id.unwrap_or_else(|| ChatId::new(0)),
msg_type, msg_type,
if msg_type2 != Viewtype::Unknown { if msg_type2 != Viewtype::Unknown {

View File

@@ -94,7 +94,7 @@ impl HtmlMsgParser {
let parsedmail = mailparse::parse_mail(rawmime)?; let parsedmail = mailparse::parse_mail(rawmime)?;
parser.collect_texts_recursive(context, &parsedmail).await?; parser.collect_texts_recursive(&parsedmail).await?;
if parser.html.is_empty() { if parser.html.is_empty() {
if let Some(plain) = &parser.plain { if let Some(plain) = &parser.plain {
@@ -117,7 +117,6 @@ impl HtmlMsgParser {
/// therefore we use the first one. /// therefore we use the first one.
fn collect_texts_recursive<'a>( fn collect_texts_recursive<'a>(
&'a mut self, &'a mut self,
context: &'a Context,
mail: &'a mailparse::ParsedMail<'a>, mail: &'a mailparse::ParsedMail<'a>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> { ) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
// Boxed future to deal with recursion // Boxed future to deal with recursion
@@ -125,7 +124,7 @@ impl HtmlMsgParser {
match get_mime_multipart_type(&mail.ctype) { match get_mime_multipart_type(&mail.ctype) {
MimeMultipartType::Multiple => { MimeMultipartType::Multiple => {
for cur_data in mail.subparts.iter() { for cur_data in mail.subparts.iter() {
self.collect_texts_recursive(context, cur_data).await? self.collect_texts_recursive(cur_data).await?
} }
Ok(()) Ok(())
} }
@@ -135,7 +134,7 @@ impl HtmlMsgParser {
return Ok(()); return Ok(());
} }
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?; let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
self.collect_texts_recursive(context, &mail).await self.collect_texts_recursive(&mail).await
} }
MimeMultipartType::Single => { MimeMultipartType::Single => {
let mimetype = mail.ctype.mimetype.parse::<Mime>()?; let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
@@ -207,7 +206,7 @@ impl HtmlMsgParser {
Ok(re) => { Ok(re) => {
self.html = re self.html = re
.replace_all( .replace_all(
&*self.html, &self.html,
format!("${{1}}{}${{3}}", replacement).as_str(), format!("${{1}}{}${{3}}", replacement).as_str(),
) )
.as_ref() .as_ref()

View File

@@ -18,7 +18,11 @@
clippy::mixed_read_write_in_expression, clippy::mixed_read_write_in_expression,
clippy::bool_assert_comparison, clippy::bool_assert_comparison,
clippy::manual_split_once, clippy::manual_split_once,
clippy::format_push_string clippy::format_push_string,
clippy::bool_to_int_with_if,
// This lint can be re-enabled once we don't target
// Rust 1.56 anymore:
clippy::collapsible_str_replace
)] )]
#[macro_use] #[macro_use]

View File

@@ -1311,7 +1311,7 @@ impl<'a> MimeFactory<'a> {
/// This line length limit is an /// This line length limit is an
/// [RFC5322 requirement](https://tools.ietf.org/html/rfc5322#section-2.1.1). /// [RFC5322 requirement](https://tools.ietf.org/html/rfc5322#section-2.1.1).
fn wrapped_base64_encode(buf: &[u8]) -> String { fn wrapped_base64_encode(buf: &[u8]) -> String {
let base64 = base64::encode(&buf); let base64 = base64::encode(buf);
let mut chars = base64.chars(); let mut chars = base64.chars();
std::iter::repeat_with(|| chars.by_ref().take(78).collect::<String>()) std::iter::repeat_with(|| chars.by_ref().take(78).collect::<String>())
.take_while(|s| !s.is_empty()) .take_while(|s| !s.is_empty())

View File

@@ -44,12 +44,12 @@ impl PlainText {
let line = line.to_string().replace('\r', ""); let line = line.to_string().replace('\r', "");
let mut line = LINKIFY_MAIL_RE let mut line = LINKIFY_MAIL_RE
.replace_all(&*line, "\rLTa href=\rQUOTmailto:$1\rQUOT\rGT$1\rLT/a\rGT") .replace_all(&line, "\rLTa href=\rQUOTmailto:$1\rQUOT\rGT$1\rLT/a\rGT")
.as_ref() .as_ref()
.to_string(); .to_string();
line = LINKIFY_URL_RE line = LINKIFY_URL_RE
.replace_all(&*line, "\rLTa href=\rQUOT$1\rQUOT\rGT$1\rLT/a\rGT") .replace_all(&line, "\rLTa href=\rQUOT$1\rQUOT\rGT$1\rLT/a\rGT")
.as_ref() .as_ref()
.to_string(); .to_string();

View File

@@ -230,7 +230,7 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Result<Qr> {
.await .await
.with_context(|| format!("can't check if address {:?} is our address", addr))? .with_context(|| format!("can't check if address {:?} is our address", addr))?
{ {
if token::exists(context, token::Namespace::InviteNumber, &*invitenumber).await { if token::exists(context, token::Namespace::InviteNumber, &invitenumber).await {
Ok(Qr::WithdrawVerifyGroup { Ok(Qr::WithdrawVerifyGroup {
grpname, grpname,
grpid, grpid,
@@ -260,7 +260,7 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Result<Qr> {
}) })
} }
} else if context.is_self_addr(addr).await? { } else if context.is_self_addr(addr).await? {
if token::exists(context, token::Namespace::InviteNumber, &*invitenumber).await { if token::exists(context, token::Namespace::InviteNumber, &invitenumber).await {
Ok(Qr::WithdrawVerifyContact { Ok(Qr::WithdrawVerifyContact {
contact_id, contact_id,
fingerprint, fingerprint,

View File

@@ -57,7 +57,7 @@ impl From<&str> for Reaction {
.split_ascii_whitespace() .split_ascii_whitespace()
.filter(|&emoji| emoji.len() < 30) .filter(|&emoji| emoji.len() < 30)
.collect(); .collect();
emojis.sort(); emojis.sort_unstable();
emojis.dedup(); emojis.dedup();
let reaction = emojis.join(" "); let reaction = emojis.join(" ");
Self { reaction } Self { reaction }
@@ -84,7 +84,7 @@ impl Reaction {
pub fn add(&self, other: Self) -> Self { pub fn add(&self, other: Self) -> Self {
let mut emojis: Vec<&str> = self.emojis(); let mut emojis: Vec<&str> = self.emojis();
emojis.append(&mut other.emojis()); emojis.append(&mut other.emojis());
emojis.sort(); emojis.sort_unstable();
emojis.dedup(); emojis.dedup();
let reaction = emojis.join(" "); let reaction = emojis.join(" ");
Self { reaction } Self { reaction }

View File

@@ -1904,7 +1904,7 @@ async fn apply_mailinglist_changes(
Contact::add_or_lookup(context, "", list_post, Origin::Hidden).await?; Contact::add_or_lookup(context, "", list_post, Origin::Hidden).await?;
let mut contact = Contact::load_from_db(context, contact_id).await?; let mut contact = Contact::load_from_db(context, contact_id).await?;
if contact.param.get(Param::ListId) != Some(listid) { if contact.param.get(Param::ListId) != Some(listid) {
contact.param.set(Param::ListId, &listid); contact.param.set(Param::ListId, listid);
contact.update_param(context).await?; contact.update_param(context).await?;
} }

View File

@@ -405,7 +405,7 @@ impl Context {
ret += " <b>"; ret += " <b>";
ret += &*escaper::encode_minimal(&foldername); ret += &*escaper::encode_minimal(&foldername);
ret += ":</b> "; ret += ":</b> ";
ret += &*escaper::encode_minimal(&*detailed.to_string_imap(self).await); ret += &*escaper::encode_minimal(&detailed.to_string_imap(self).await);
ret += "</li>"; ret += "</li>";
folder_added = true; folder_added = true;

View File

@@ -272,7 +272,7 @@ pub(crate) fn create_id() -> String {
rng.fill(&mut arr[..]); rng.fill(&mut arr[..]);
// Take 11 base64 characters containing 66 random bits. // Take 11 base64 characters containing 66 random bits.
base64::encode_config(&arr, base64::URL_SAFE) base64::encode_config(arr, base64::URL_SAFE)
.chars() .chars()
.take(11) .take(11)
.collect() .collect()

View File

@@ -496,7 +496,7 @@ impl Context {
for update_item in updates.updates { for update_item in updates.updates {
self.create_status_update_record( self.create_status_update_record(
&mut instance, &mut instance,
&*serde_json::to_string(&update_item)?, &serde_json::to_string(&update_item)?,
timestamp, timestamp,
can_info_msg, can_info_msg,
from_id, from_id,
@@ -545,7 +545,7 @@ impl Context {
let (update_item_str, serial) = row; let (update_item_str, serial) = row;
let update_item = StatusUpdateItemAndSerial let update_item = StatusUpdateItemAndSerial
{ {
item: serde_json::from_str(&*update_item_str)?, item: serde_json::from_str(&update_item_str)?,
serial, serial,
max_serial, max_serial,
}; };
@@ -553,7 +553,7 @@ impl Context {
if !json.is_empty() { if !json.is_empty() {
json.push_str(",\n"); json.push_str(",\n");
} }
json.push_str(&*serde_json::to_string(&update_item)?); json.push_str(&serde_json::to_string(&update_item)?);
} }
Ok(json) Ok(json)
}, },
@@ -1825,7 +1825,7 @@ sth_for_the = "future""#
let instance = t.get_last_msg().await; let instance = t.get_last_msg().await;
let html = instance.get_webxdc_blob(&t, "index.html").await?; let html = instance.get_webxdc_blob(&t, "index.html").await?;
assert!(String::from_utf8_lossy(&*html).contains("requires a newer Delta Chat version")); assert!(String::from_utf8_lossy(&html).contains("requires a newer Delta Chat version"));
Ok(()) Ok(())
} }