New version of clippy has a lot of new lints

Lots of new clippy lints due to toolchain upgrade.

Made the Message::error field pub(crate) again, it was the odd one out
and it seemed a reasonable way to shut up clippy.
This commit is contained in:
Floris Bruynooghe
2021-01-18 22:57:41 +01:00
parent 2435803fa3
commit 83dd1c6232
10 changed files with 98 additions and 86 deletions

View File

@@ -1555,10 +1555,9 @@ pub unsafe extern "C" fn dc_create_contact(
let name = to_string_lossy(name); let name = to_string_lossy(name);
block_on(async move { block_on(async move {
match Contact::create(&ctx, name, to_string_lossy(addr)).await { Contact::create(&ctx, name, to_string_lossy(addr))
Ok(id) => id, .await
Err(_) => 0, .unwrap_or(0)
}
}) })
} }

View File

@@ -256,9 +256,11 @@ impl ChatId {
}; };
if promote { if promote {
let mut msg = Message::default(); let mut msg = Message {
msg.viewtype = Viewtype::Text; viewtype: Viewtype::Text,
msg.text = Some(msg_text); text: Some(msg_text),
..Default::default()
};
msg.param.set_cmd(cmd); msg.param.set_cmd(cmd);
send_msg(context, self, &mut msg).await?; send_msg(context, self, &mut msg).await?;
} else { } else {

View File

@@ -428,7 +428,7 @@ async fn decrypt_setup_file<T: std::io::Read + std::io::Seek>(
pub fn normalize_setup_code(s: &str) -> String { pub fn normalize_setup_code(s: &str) -> String {
let mut out = String::new(); let mut out = String::new();
for c in s.chars() { for c in s.chars() {
if c >= '0' && c <= '9' { if ('0'..='9').contains(&c) {
out.push(c); out.push(c);
if let 4 | 9 | 14 | 19 | 24 | 29 | 34 | 39 = out.len() { if let 4 | 9 | 14 | 19 | 24 | 29 | 34 | 39 = out.len() {
out += "-" out += "-"

View File

@@ -407,7 +407,7 @@ impl std::str::FromStr for Fingerprint {
let hex_repr: String = input let hex_repr: String = input
.to_uppercase() .to_uppercase()
.chars() .chars()
.filter(|&c| c >= '0' && c <= '9' || c >= 'A' && c <= 'F') .filter(|&c| ('0'..='9').contains(&c) || ('A'..='F').contains(&c))
.collect(); .collect();
let v: Vec<u8> = hex::decode(hex_repr)?; let v: Vec<u8> = hex::decode(hex_repr)?;
let fp = Fingerprint::new(v)?; let fp = Fingerprint::new(v)?;

View File

@@ -310,16 +310,16 @@ pub struct Message {
pub(crate) mime_modified: bool, pub(crate) mime_modified: bool,
pub(crate) chat_blocked: Blocked, pub(crate) chat_blocked: Blocked,
pub(crate) location_id: u32, pub(crate) location_id: u32,
error: Option<String>, pub(crate) error: Option<String>,
pub(crate) param: Params, pub(crate) param: Params,
} }
impl Message { impl Message {
pub fn new(viewtype: Viewtype) -> Self { pub fn new(viewtype: Viewtype) -> Self {
let mut msg = Message::default(); Message {
msg.viewtype = viewtype; viewtype,
..Default::default()
msg }
} }
pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message, Error> { pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message, Error> {
@@ -360,55 +360,53 @@ impl Message {
), ),
paramsv![id], paramsv![id],
|row| { |row| {
let mut msg = Message::default(); let text = match row.get_raw("txt") {
// msg.id = row.get::<_, AnyMsgId>("id")?; rusqlite::types::ValueRef::Text(buf) => {
msg.id = row.get("id")?; match String::from_utf8(buf.to_vec()) {
msg.rfc724_mid = row.get::<_, String>("rfc724mid")?; Ok(t) => t,
msg.in_reply_to = row.get::<_, Option<String>>("mime_in_reply_to")?; Err(_) => {
msg.server_folder = row.get::<_, Option<String>>("server_folder")?; warn!(
msg.server_uid = row.get("server_uid")?; context,
msg.chat_id = row.get("chat_id")?; concat!(
msg.from_id = row.get("from_id")?; "dc_msg_load_from_db: could not get ",
msg.to_id = row.get("to_id")?; "text column as non-lossy utf8 id {}"
msg.timestamp_sort = row.get("timestamp")?; ),
msg.timestamp_sent = row.get("timestamp_sent")?; id
msg.timestamp_rcvd = row.get("timestamp_rcvd")?; );
msg.ephemeral_timer = row.get("ephemeral_timer")?; String::from_utf8_lossy(buf).into_owned()
msg.ephemeral_timestamp = row.get("ephemeral_timestamp")?; }
msg.viewtype = row.get("type")?; }
msg.state = row.get("state")?;
let error: String = row.get("error")?;
msg.error = Some(error).filter(|error| !error.is_empty());
msg.is_dc_message = row.get("msgrmsg")?;
msg.mime_modified = row.get("mime_modified")?;
let text;
if let rusqlite::types::ValueRef::Text(buf) = row.get_raw("txt") {
if let Ok(t) = String::from_utf8(buf.to_vec()) {
text = t;
} else {
warn!(
context,
concat!(
"dc_msg_load_from_db: could not get ",
"text column as non-lossy utf8 id {}"
),
id
);
text = String::from_utf8_lossy(buf).into_owned();
} }
} else { _ => String::new(),
text = "".to_string(); };
} let msg = Message {
msg.text = Some(text); id: row.get("id")?,
rfc724_mid: row.get::<_, String>("rfc724mid")?,
msg.param = row.get::<_, String>("param")?.parse().unwrap_or_default(); in_reply_to: row.get::<_, Option<String>>("mime_in_reply_to")?,
msg.hidden = row.get("hidden")?; server_folder: row.get::<_, Option<String>>("server_folder")?,
msg.location_id = row.get("location")?; server_uid: row.get("server_uid")?,
msg.chat_blocked = row chat_id: row.get("chat_id")?,
.get::<_, Option<Blocked>>("blocked")? from_id: row.get("from_id")?,
.unwrap_or_default(); to_id: row.get("to_id")?,
timestamp_sort: row.get("timestamp")?,
timestamp_sent: row.get("timestamp_sent")?,
timestamp_rcvd: row.get("timestamp_rcvd")?,
ephemeral_timer: row.get("ephemeral_timer")?,
ephemeral_timestamp: row.get("ephemeral_timestamp")?,
viewtype: row.get("type")?,
state: row.get("state")?,
error: Some(row.get::<_, String>("error")?)
.filter(|error| !error.is_empty()),
is_dc_message: row.get("msgrmsg")?,
mime_modified: row.get("mime_modified")?,
text: Some(text),
param: row.get::<_, String>("param")?.parse().unwrap_or_default(),
hidden: row.get("hidden")?,
location_id: row.get("location")?,
chat_blocked: row
.get::<_, Option<Blocked>>("blocked")?
.unwrap_or_default(),
};
Ok(msg) Ok(msg)
}, },
) )
@@ -1205,7 +1203,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
ret += &format!("\nMessage-ID: {}", msg.rfc724_mid); ret += &format!("\nMessage-ID: {}", msg.rfc724_mid);
} }
if let Some(ref server_folder) = msg.server_folder { if let Some(ref server_folder) = msg.server_folder {
if server_folder != "" { if !server_folder.is_empty() {
ret += &format!("\nLast seen as: {}/{}", server_folder, msg.server_uid); ret += &format!("\nLast seen as: {}/{}", server_folder, msg.server_uid);
} }
} }

View File

@@ -864,8 +864,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
if let Some(grpimage) = grpimage { if let Some(grpimage) = grpimage {
info!(self.context, "setting group image '{}'", grpimage); info!(self.context, "setting group image '{}'", grpimage);
let mut meta = Message::default(); let mut meta = Message {
meta.viewtype = Viewtype::Image; viewtype: Viewtype::Image,
..Default::default()
};
meta.param.set(Param::File, grpimage); meta.param.set(Param::File, grpimage);
let (mail, filename_as_sent) = build_body_file(context, &meta, "group-image").await?; let (mail, filename_as_sent) = build_body_file(context, &meta, "group-image").await?;

View File

@@ -438,8 +438,10 @@ impl MimeMessage {
// Besides, we want to show something in case our incoming-processing // Besides, we want to show something in case our incoming-processing
// failed to properly handle an incoming message. // failed to properly handle an incoming message.
if self.parts.is_empty() && self.mdn_reports.is_empty() { if self.parts.is_empty() && self.mdn_reports.is_empty() {
let mut part = Part::default(); let mut part = Part {
part.typ = Viewtype::Text; typ: Viewtype::Text,
..Default::default()
};
if let Some(ref subject) = self.get_subject() { if let Some(ref subject) = self.get_subject() {
if !self.has_chat_version() { if !self.has_chat_version() {
@@ -617,12 +619,13 @@ impl MimeMessage {
let msg_body = context.stock_str(StockMessage::CantDecryptMsgBody).await; let msg_body = context.stock_str(StockMessage::CantDecryptMsgBody).await;
let txt = format!("[{}]", msg_body); let txt = format!("[{}]", msg_body);
let mut part = Part::default(); let part = Part {
part.typ = Viewtype::Text; typ: Viewtype::Text,
part.msg_raw = Some(txt.clone()); msg_raw: Some(txt.clone()),
part.msg = txt; msg: txt,
part.error = Some("Decryption failed".to_string()); error: Some("Decryption failed".to_string()),
..Default::default()
};
self.parts.push(part); self.parts.push(part);
any_part_added = true; any_part_added = true;
@@ -654,8 +657,10 @@ impl MimeMessage {
// downloading the message again and // downloading the message again and
// delete if automatic message deletion is // delete if automatic message deletion is
// enabled. // enabled.
let mut part = Part::default(); let part = Part {
part.typ = Viewtype::Unknown; typ: Viewtype::Unknown,
..Default::default()
};
self.parts.push(part); self.parts.push(part);
any_part_added = true; any_part_added = true;
@@ -783,11 +788,13 @@ impl MimeMessage {
}; };
if !simplified_txt.is_empty() || simplified_quote.is_some() { if !simplified_txt.is_empty() || simplified_quote.is_some() {
let mut part = Part::default(); let mut part = Part {
part.dehtml_failed = dehtml_failed; dehtml_failed,
part.typ = Viewtype::Text; typ: Viewtype::Text,
part.mimetype = Some(mime_type); mimetype: Some(mime_type),
part.msg = simplified_txt; msg: simplified_txt,
..Default::default()
};
if let Some(quote) = simplified_quote { if let Some(quote) = simplified_quote {
part.param.set(Param::Quote, quote); part.param.set(Param::Quote, quote);
} }

View File

@@ -385,10 +385,12 @@ async fn send_handshake_msg(
fingerprint: Option<Fingerprint>, fingerprint: Option<Fingerprint>,
grpid: impl AsRef<str>, grpid: impl AsRef<str>,
) -> Result<(), SendMsgError> { ) -> Result<(), SendMsgError> {
let mut msg = Message::default(); let mut msg = Message {
msg.viewtype = Viewtype::Text; viewtype: Viewtype::Text,
msg.text = Some(format!("Secure-Join: {}", step)); text: Some(format!("Secure-Join: {}", step)),
msg.hidden = true; hidden: true,
..Default::default()
};
msg.param.set_cmd(SystemMessage::SecurejoinMessage); msg.param.set_cmd(SystemMessage::SecurejoinMessage);
if step.is_empty() { if step.is_empty() {
msg.param.remove(Param::Arg); msg.param.remove(Param::Arg);

View File

@@ -31,7 +31,9 @@ fn remove_message_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) {
// use that only when no other footer is found // use that only when no other footer is found
// and if the line before is empty and the line after is not empty // and if the line before is empty and the line after is not empty
"--" => { "--" => {
if (ix == 0 || lines[ix - 1] == "") && ix != lines.len() - 1 && lines[ix + 1] != "" if (ix == 0 || lines[ix - 1].is_empty())
&& ix != lines.len() - 1
&& !lines[ix + 1].is_empty()
{ {
nearly_standard_footer = Some(ix); nearly_standard_footer = Some(ix);
} }

View File

@@ -504,7 +504,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
&contact_name, &contact_name,
contact_id, contact_id,
msgtext.unwrap_or_default(), msgtext.unwrap_or_default(),
if msg.get_from_id() == 1 as libc::c_uint { if msg.get_from_id() == 1u32 {
"" ""
} else if msg.get_state() == MessageState::InSeen { } else if msg.get_state() == MessageState::InSeen {
"[SEEN]" "[SEEN]"