Fix cargo clippy and doc errors after Rust update to 1.66

This commit is contained in:
iequidoo
2022-12-15 17:31:57 -03:00
committed by iequidoo
parent 2cd63234c1
commit c3a0bb2b77
15 changed files with 37 additions and 46 deletions

View File

@@ -5,7 +5,6 @@
### Changes ### Changes
- Don't use deprecated `chrono` functions #3798 - Don't use deprecated `chrono` functions #3798
- Document accounts manager #3837 - Document accounts manager #3837
- If a classical-email-user sends an email to a group and adds new recipients, - If a classical-email-user sends an email to a group and adds new recipients,
add the new recipients as group members #3781 add the new recipients as group members #3781
- Remove `pytest-async` plugin #3846 - Remove `pytest-async` plugin #3846
@@ -16,6 +15,7 @@
- Set read/write timeouts for IMAP over SOCKS5 #3833 - Set read/write timeouts for IMAP over SOCKS5 #3833
- Treat attached PGP keys as peer keys with mutual encryption preference #3832 - Treat attached PGP keys as peer keys with mutual encryption preference #3832
- fix migration of old databases #3842 - fix migration of old databases #3842
- Fix cargo clippy and doc errors after Rust update to 1.66 #3850
## 1.103.0 ## 1.103.0

View File

@@ -2182,7 +2182,7 @@ pub unsafe extern "C" fn dc_imex(
eprintln!("ignoring careless call to dc_imex()"); eprintln!("ignoring careless call to dc_imex()");
return; return;
} }
let what = match imex::ImexMode::from_i32(what_raw as i32) { let what = match imex::ImexMode::from_i32(what_raw) {
Some(what) => what, Some(what) => what,
None => { None => {
eprintln!("ignoring invalid argument {} to dc_imex", what_raw); eprintln!("ignoring invalid argument {} to dc_imex", what_raw);
@@ -2253,10 +2253,7 @@ pub unsafe extern "C" fn dc_continue_key_transfer(
msg_id: u32, msg_id: u32,
setup_code: *const libc::c_char, setup_code: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
if context.is_null() if context.is_null() || msg_id <= constants::DC_MSG_ID_LAST_SPECIAL || setup_code.is_null() {
|| msg_id <= constants::DC_MSG_ID_LAST_SPECIAL as u32
|| setup_code.is_null()
{
eprintln!("ignoring careless call to dc_continue_key_transfer()"); eprintln!("ignoring careless call to dc_continue_key_transfer()");
return 0; return 0;
} }
@@ -2447,15 +2444,9 @@ pub unsafe extern "C" fn dc_get_locations(
}; };
block_on(async move { block_on(async move {
let res = location::get_range( let res = location::get_range(ctx, chat_id, contact_id, timestamp_begin, timestamp_end)
ctx, .await
chat_id, .unwrap_or_log_default(ctx, "Failed get_locations");
contact_id,
timestamp_begin as i64,
timestamp_end as i64,
)
.await
.unwrap_or_log_default(ctx, "Failed get_locations");
Box::into_raw(Box::new(dc_array_t::from(res))) Box::into_raw(Box::new(dc_array_t::from(res)))
}) })
} }
@@ -2702,7 +2693,7 @@ pub unsafe extern "C" fn dc_chatlist_get_chat_id(
} }
let ffi_list = &*chatlist; let ffi_list = &*chatlist;
let ctx = &*ffi_list.context; let ctx = &*ffi_list.context;
match ffi_list.list.get_chat_id(index as usize) { match ffi_list.list.get_chat_id(index) {
Ok(chat_id) => chat_id.to_u32(), Ok(chat_id) => chat_id.to_u32(),
Err(err) => { Err(err) => {
warn!(ctx, "get_chat_id failed: {}", err); warn!(ctx, "get_chat_id failed: {}", err);
@@ -2722,7 +2713,7 @@ pub unsafe extern "C" fn dc_chatlist_get_msg_id(
} }
let ffi_list = &*chatlist; let ffi_list = &*chatlist;
let ctx = &*ffi_list.context; let ctx = &*ffi_list.context;
match ffi_list.list.get_msg_id(index as usize) { match ffi_list.list.get_msg_id(index) {
Ok(msg_id) => msg_id.map_or(0, |msg_id| msg_id.to_u32()), Ok(msg_id) => msg_id.map_or(0, |msg_id| msg_id.to_u32()),
Err(err) => { Err(err) => {
warn!(ctx, "get_msg_id failed: {}", err); warn!(ctx, "get_msg_id failed: {}", err);
@@ -2753,7 +2744,7 @@ pub unsafe extern "C" fn dc_chatlist_get_summary(
block_on(async move { block_on(async move {
let summary = ffi_list let summary = ffi_list
.list .list
.get_summary(ctx, index as usize, maybe_chat) .get_summary(ctx, index, maybe_chat)
.await .await
.log_err(ctx, "get_summary failed") .log_err(ctx, "get_summary failed")
.unwrap_or_default(); .unwrap_or_default();

View File

@@ -746,7 +746,7 @@ mod tests {
assert!(file_size(&avatar_blob).await <= 3000); assert!(file_size(&avatar_blob).await <= 3000);
assert!(file_size(&avatar_blob).await > 2000); assert!(file_size(&avatar_blob).await > 2000);
tokio::task::block_in_place(move || { tokio::task::block_in_place(move || {
let img = image::open(&avatar_blob).unwrap(); let img = image::open(avatar_blob).unwrap();
assert!(img.width() > 130); assert!(img.width() > 130);
assert_eq!(img.width(), img.height()); assert_eq!(img.width(), img.height());
}); });

View File

@@ -768,7 +768,7 @@ impl ChatId {
paramsv![self], paramsv![self],
) )
.await?; .await?;
Ok(count as usize) Ok(count)
} }
pub async fn get_fresh_msg_cnt(self, context: &Context) -> Result<usize> { pub async fn get_fresh_msg_cnt(self, context: &Context) -> Result<usize> {
@@ -793,7 +793,7 @@ impl ChatId {
paramsv![MessageState::InFresh, self], paramsv![MessageState::InFresh, self],
) )
.await?; .await?;
Ok(count as usize) Ok(count)
} }
pub(crate) async fn get_param(self, context: &Context) -> Result<Params> { pub(crate) async fn get_param(self, context: &Context) -> Result<Params> {
@@ -1474,7 +1474,7 @@ impl Chat {
new_rfc724_mid, new_rfc724_mid,
self.id, self.id,
ContactId::SELF, ContactId::SELF,
to_id as i32, to_id,
timestamp, timestamp,
msg.viewtype, msg.viewtype,
msg.state, msg.state,
@@ -1522,7 +1522,7 @@ impl Chat {
new_rfc724_mid, new_rfc724_mid,
self.id, self.id,
ContactId::SELF, ContactId::SELF,
to_id as i32, to_id,
timestamp, timestamp,
msg.viewtype, msg.viewtype,
msg.state, msg.state,
@@ -3261,7 +3261,7 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
paramsv![], paramsv![],
) )
.await?; .await?;
Ok(count as usize) Ok(count)
} else { } else {
Ok(0) Ok(0)
} }

View File

@@ -204,7 +204,7 @@ impl Context {
let value = match key { let value = match key {
Config::Selfavatar => { Config::Selfavatar => {
let rel_path = self.sql.get_raw_config(key.as_ref()).await?; let rel_path = self.sql.get_raw_config(key.as_ref()).await?;
rel_path.map(|p| get_abs_path(self, &p).to_string_lossy().into_owned()) rel_path.map(|p| get_abs_path(self, p).to_string_lossy().into_owned())
} }
Config::SysVersion => Some((*DC_VERSION_STR).clone()), Config::SysVersion => Some((*DC_VERSION_STR).clone()),
Config::SysMsgsizeMaxRecommended => Some(format!("{}", RECOMMENDED_FILE_SIZE)), Config::SysMsgsizeMaxRecommended => Some(format!("{}", RECOMMENDED_FILE_SIZE)),

View File

@@ -855,7 +855,7 @@ impl Contact {
paramsv![ContactId::LAST_SPECIAL], paramsv![ContactId::LAST_SPECIAL],
) )
.await?; .await?;
Ok(count as usize) Ok(count)
} }
/// Get blocked contacts. /// Get blocked contacts.

View File

@@ -528,10 +528,10 @@ impl Context {
let l2 = LoginParam::load_configured_params(self).await?; let l2 = LoginParam::load_configured_params(self).await?;
let secondary_addrs = self.get_secondary_self_addrs().await?.join(", "); let secondary_addrs = self.get_secondary_self_addrs().await?.join(", ");
let displayname = self.get_config(Config::Displayname).await?; let displayname = self.get_config(Config::Displayname).await?;
let chats = get_chat_cnt(self).await? as usize; let chats = get_chat_cnt(self).await?;
let unblocked_msgs = message::get_unblocked_msg_cnt(self).await as usize; let unblocked_msgs = message::get_unblocked_msg_cnt(self).await;
let request_msgs = message::get_request_msg_cnt(self).await as usize; let request_msgs = message::get_request_msg_cnt(self).await;
let contacts = Contact::get_real_cnt(self).await? as usize; let contacts = Contact::get_real_cnt(self).await?;
let is_configured = self.get_config_int(Config::Configured).await?; let is_configured = self.get_config_int(Config::Configured).await?;
let socks5_enabled = self.get_config_int(Config::Socks5Enabled).await?; let socks5_enabled = self.get_config_int(Config::Socks5Enabled).await?;
let dbversion = self let dbversion = self

View File

@@ -20,7 +20,7 @@ struct Dehtml {
/// increased at each `<div>` and decreased at each `</div>`. This way we know when the quote ends. /// increased at each `<div>` and decreased at each `</div>`. This way we know when the quote ends.
/// If this is > `0`, then we are inside a `<div name="quote">` /// If this is > `0`, then we are inside a `<div name="quote">`
divs_since_quote_div: u32, divs_since_quote_div: u32,
/// Everything between <div name="quote"> and <div name="quoted-content"> is usually metadata /// Everything between `<div name="quote">` and `<div name="quoted-content">` is usually metadata
/// If this is > `0`, then we are inside a `<div name="quoted-content">`. /// If this is > `0`, then we are inside a `<div name="quoted-content">`.
divs_since_quoted_content_div: u32, divs_since_quoted_content_div: u32,
/// All-Inkl just puts the quote into `<blockquote> </blockquote>`. This count is /// All-Inkl just puts the quote into `<blockquote> </blockquote>`. This count is
@@ -42,7 +42,7 @@ impl Dehtml {
} }
fn get_add_text(&self) -> AddText { fn get_add_text(&self) -> AddText {
if self.divs_since_quote_div > 0 && self.divs_since_quoted_content_div == 0 { if self.divs_since_quote_div > 0 && self.divs_since_quoted_content_div == 0 {
AddText::No // Everything between <div name="quoted"> and <div name="quoted_content"> is metadata which we don't want AddText::No // Everything between `<div name="quoted">` and `<div name="quoted_content">` is metadata which we don't want
} else { } else {
self.add_text self.add_text
} }

View File

@@ -234,7 +234,7 @@ impl HtmlMsgParser {
/// Convert a mime part to a data: url as defined in [RFC 2397](https://tools.ietf.org/html/rfc2397). /// Convert a mime part to a data: url as defined in [RFC 2397](https://tools.ietf.org/html/rfc2397).
fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result<String> { fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result<String> {
let data = mail.get_body_raw()?; let data = mail.get_body_raw()?;
let data = base64::encode(&data); let data = base64::encode(data);
Ok(format!("data:{};base64,{}", mail.ctype.mimetype, data)) Ok(format!("data:{};base64,{}", mail.ctype.mimetype, data))
} }

View File

@@ -241,7 +241,7 @@ pub(crate) async fn perform_job(context: &Context, mut connection: Connection<'_
info!( info!(
context, context,
"job #{} not succeeded on try #{}, retry in {} seconds.", "job #{} not succeeded on try #{}, retry in {} seconds.",
job.job_id as u32, job.job_id,
tries, tries,
time_offset time_offset
); );

View File

@@ -74,7 +74,7 @@ pub trait DcKey: Serialize + Deserializable + KeyTrait + Clone {
/// Serialise the key to a base64 string. /// Serialise the key to a base64 string.
fn to_base64(&self) -> String { fn to_base64(&self) -> String {
base64::encode(&DcKey::to_bytes(self)) base64::encode(DcKey::to_bytes(self))
} }
/// Serialise the key to ASCII-armored representation. /// Serialise the key to ASCII-armored representation.

View File

@@ -579,8 +579,8 @@ impl Message {
pub fn has_deviating_timestamp(&self) -> bool { pub fn has_deviating_timestamp(&self) -> bool {
let cnv_to_local = gm2local_offset(); let cnv_to_local = gm2local_offset();
let sort_timestamp = self.get_sort_timestamp() as i64 + cnv_to_local; let sort_timestamp = self.get_sort_timestamp() + cnv_to_local;
let send_timestamp = self.get_timestamp() as i64 + cnv_to_local; let send_timestamp = self.get_timestamp() + cnv_to_local;
sort_timestamp / 86400 != send_timestamp / 86400 sort_timestamp / 86400 != send_timestamp / 86400
} }

View File

@@ -131,7 +131,7 @@ pub enum Param {
/// For Chats /// For Chats
Selftalk = b'K', Selftalk = b'K',
/// For Chats: On sending a new message we set the subject to "Re: <last subject>". /// For Chats: On sending a new message we set the subject to `Re: <last subject>`.
/// Usually we just use the subject of the parent message, but if the parent message /// Usually we just use the subject of the parent message, but if the parent message
/// is deleted, we use the LastSubject of the chat. /// is deleted, we use the LastSubject of the chat.
LastSubject = b't', LastSubject = b't',

View File

@@ -236,13 +236,13 @@ impl Sql {
// When auto_vacuum is INCREMENTAL, it is possible to // When auto_vacuum is INCREMENTAL, it is possible to
// use PRAGMA incremental_vacuum to return unused // use PRAGMA incremental_vacuum to return unused
// database pages to the filesystem. // database pages to the filesystem.
conn.pragma_update(None, "auto_vacuum", &"INCREMENTAL".to_string())?; conn.pragma_update(None, "auto_vacuum", "INCREMENTAL".to_string())?;
// journal_mode is persisted, it is sufficient to change it only for one handle. // journal_mode is persisted, it is sufficient to change it only for one handle.
conn.pragma_update(None, "journal_mode", &"WAL".to_string())?; conn.pragma_update(None, "journal_mode", "WAL".to_string())?;
// Default synchronous=FULL is much slower. NORMAL is sufficient for WAL mode. // Default synchronous=FULL is much slower. NORMAL is sufficient for WAL mode.
conn.pragma_update(None, "synchronous", &"NORMAL".to_string())?; conn.pragma_update(None, "synchronous", "NORMAL".to_string())?;
Ok(()) Ok(())
})?; })?;
} }
@@ -459,7 +459,7 @@ impl Sql {
let conn = self.get_conn().await?; let conn = self.get_conn().await?;
tokio::task::block_in_place(move || { tokio::task::block_in_place(move || {
let mut exists = false; let mut exists = false;
conn.pragma(None, "table_info", &name.to_string(), |_row| { conn.pragma(None, "table_info", name.to_string(), |_row| {
// will only be executed if the info was found // will only be executed if the info was found
exists = true; exists = true;
Ok(()) Ok(())
@@ -476,7 +476,7 @@ impl Sql {
let mut exists = false; let mut exists = false;
// `PRAGMA table_info` returns one row per column, // `PRAGMA table_info` returns one row per column,
// each row containing 0=cid, 1=name, 2=type, 3=notnull, 4=dflt_value // each row containing 0=cid, 1=name, 2=type, 3=notnull, 4=dflt_value
conn.pragma(None, "table_info", &table_name.to_string(), |row| { conn.pragma(None, "table_info", table_name.to_string(), |row| {
let curr_name: String = row.get(1)?; let curr_name: String = row.get(1)?;
if col_name == curr_name { if col_name == curr_name {
exists = true; exists = true;

View File

@@ -273,7 +273,7 @@ async fn maybe_warn_on_outdated(context: &Context, now: i64, approx_compile_time
/// IDs generated by this function are 66 bit wide and are returned as 11 base64 characters. /// IDs generated by this function are 66 bit wide and are returned as 11 base64 characters.
/// ///
/// Additional information when used as a message-id or group-id: /// Additional information when used as a message-id or group-id:
/// - for OUTGOING messages this ID is written to the header as `Chat-Group-ID:` and is added to the message ID as Gr.<grpid>.<random>@<random> /// - for OUTGOING messages this ID is written to the header as `Chat-Group-ID:` and is added to the message ID as `Gr.<grpid>.<random>@<random>`
/// - for INCOMING messages, the ID is taken from the Chat-Group-ID-header or from the Message-ID in the In-Reply-To: or References:-Header /// - for INCOMING messages, the ID is taken from the Chat-Group-ID-header or from the Message-ID in the In-Reply-To: or References:-Header
/// - the group-id should be a string with the characters [a-zA-Z0-9\-_] /// - the group-id should be a string with the characters [a-zA-Z0-9\-_]
pub(crate) fn create_id() -> String { pub(crate) fn create_id() -> String {
@@ -361,7 +361,7 @@ pub(crate) fn get_abs_path(context: &Context, path: impl AsRef<Path>) -> PathBuf
pub(crate) async fn get_filebytes(context: &Context, path: impl AsRef<Path>) -> u64 { pub(crate) async fn get_filebytes(context: &Context, path: impl AsRef<Path>) -> u64 {
let path_abs = get_abs_path(context, &path); let path_abs = get_abs_path(context, &path);
match fs::metadata(&path_abs).await { match fs::metadata(&path_abs).await {
Ok(meta) => meta.len() as u64, Ok(meta) => meta.len(),
Err(_err) => 0, Err(_err) => 0,
} }
} }
@@ -494,7 +494,7 @@ pub fn open_file_std<P: AsRef<std::path::Path>>(
let p: PathBuf = path.as_ref().into(); let p: PathBuf = path.as_ref().into();
let path_abs = get_abs_path(context, p); let path_abs = get_abs_path(context, p);
match std::fs::File::open(&path_abs) { match std::fs::File::open(path_abs) {
Ok(bytes) => Ok(bytes), Ok(bytes) => Ok(bytes),
Err(err) => { Err(err) => {
warn!( warn!(