mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 13:26:38 +03:00
Reduce number of unsafe as conversions
Enable clippy::cast_lossless lint and get rid of some conversions pointed out by clippy::as_conversions.
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- refactorings #3026
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- avoid archived, fresh chats #3053
|
- avoid archived, fresh chats #3053
|
||||||
|
|
||||||
|
|||||||
@@ -960,7 +960,7 @@ impl std::fmt::Display for ChatId {
|
|||||||
/// well as query for a [ChatId].
|
/// well as query for a [ChatId].
|
||||||
impl rusqlite::types::ToSql for ChatId {
|
impl rusqlite::types::ToSql for ChatId {
|
||||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
||||||
let val = rusqlite::types::Value::Integer(self.0 as i64);
|
let val = rusqlite::types::Value::Integer(i64::from(self.0));
|
||||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
@@ -970,7 +970,7 @@ impl rusqlite::types::ToSql for ChatId {
|
|||||||
impl rusqlite::types::FromSql for ChatId {
|
impl rusqlite::types::FromSql for ChatId {
|
||||||
fn column_result(value: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult<Self> {
|
fn column_result(value: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult<Self> {
|
||||||
i64::column_result(value).and_then(|val| {
|
i64::column_result(value).and_then(|val| {
|
||||||
if 0 <= val && val <= std::u32::MAX as i64 {
|
if 0 <= val && val <= i64::from(std::u32::MAX) {
|
||||||
Ok(ChatId::new(val as u32))
|
Ok(ChatId::new(val as u32))
|
||||||
} else {
|
} else {
|
||||||
Err(rusqlite::types::FromSqlError::OutOfRange(val))
|
Err(rusqlite::types::FromSqlError::OutOfRange(val))
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ impl Context {
|
|||||||
match self.get_config_int(Config::DeleteServerAfter).await? {
|
match self.get_config_int(Config::DeleteServerAfter).await? {
|
||||||
0 => Ok(None),
|
0 => Ok(None),
|
||||||
1 => Ok(Some(0)),
|
1 => Ok(Some(0)),
|
||||||
x => Ok(Some(x as i64)),
|
x => Ok(Some(i64::from(x))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ impl Context {
|
|||||||
pub async fn get_config_delete_device_after(&self) -> Result<Option<i64>> {
|
pub async fn get_config_delete_device_after(&self) -> Result<Option<i64>> {
|
||||||
match self.get_config_int(Config::DeleteDeviceAfter).await? {
|
match self.get_config_int(Config::DeleteDeviceAfter).await? {
|
||||||
0 => Ok(None),
|
0 => Ok(None),
|
||||||
x => Ok(Some(x as i64)),
|
x => Ok(Some(i64::from(x))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1156,8 +1156,8 @@ INSERT INTO msgs
|
|||||||
stmt.execute(paramsv![
|
stmt.execute(paramsv![
|
||||||
rfc724_mid,
|
rfc724_mid,
|
||||||
chat_id,
|
chat_id,
|
||||||
if trash { 0 } else { from_id as i32 },
|
if trash { 0 } else { i64::from(from_id) },
|
||||||
if trash { 0 } else { to_id as i32 },
|
if trash { 0 } else { i64::from(to_id) },
|
||||||
sort_timestamp,
|
sort_timestamp,
|
||||||
sent_timestamp,
|
sent_timestamp,
|
||||||
rcvd_timestamp,
|
rcvd_timestamp,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ pub(crate) fn dc_gm2local_offset() -> i64 {
|
|||||||
/* returns the offset that must be _added_ to an UTC/GMT-time to create the localtime.
|
/* returns the offset that must be _added_ to an UTC/GMT-time to create the localtime.
|
||||||
the function may return negative values. */
|
the function may return negative values. */
|
||||||
let lt = Local::now();
|
let lt = Local::now();
|
||||||
lt.offset().local_minus_utc() as i64
|
i64::from(lt.offset().local_minus_utc())
|
||||||
}
|
}
|
||||||
|
|
||||||
// timesmearing
|
// timesmearing
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ impl Job {
|
|||||||
"UPDATE jobs SET desired_timestamp=?, tries=?, param=? WHERE id=?;",
|
"UPDATE jobs SET desired_timestamp=?, tries=?, param=? WHERE id=?;",
|
||||||
paramsv![
|
paramsv![
|
||||||
self.desired_timestamp,
|
self.desired_timestamp,
|
||||||
self.tries as i64,
|
i64::from(self.tries),
|
||||||
self.param.to_string(),
|
self.param.to_string(),
|
||||||
self.job_id as i32,
|
self.job_id as i32,
|
||||||
],
|
],
|
||||||
@@ -676,7 +676,7 @@ fn get_backoff_time_offset(tries: u32, action: Action) -> i64 {
|
|||||||
if seconds < 1 {
|
if seconds < 1 {
|
||||||
seconds = 1;
|
seconds = 1;
|
||||||
}
|
}
|
||||||
seconds as i64
|
i64::from(seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
clippy::all,
|
clippy::all,
|
||||||
clippy::indexing_slicing,
|
clippy::indexing_slicing,
|
||||||
clippy::wildcard_imports,
|
clippy::wildcard_imports,
|
||||||
clippy::needless_borrow
|
clippy::needless_borrow,
|
||||||
|
clippy::cast_lossless
|
||||||
)]
|
)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::match_bool,
|
clippy::match_bool,
|
||||||
|
|||||||
@@ -253,7 +253,8 @@ impl LoginParam {
|
|||||||
sql.set_raw_config(key, Some(&self.imap.server)).await?;
|
sql.set_raw_config(key, Some(&self.imap.server)).await?;
|
||||||
|
|
||||||
let key = format!("{}mail_port", prefix);
|
let key = format!("{}mail_port", prefix);
|
||||||
sql.set_raw_config_int(key, self.imap.port as i32).await?;
|
sql.set_raw_config_int(key, i32::from(self.imap.port))
|
||||||
|
.await?;
|
||||||
|
|
||||||
let key = format!("{}mail_user", prefix);
|
let key = format!("{}mail_user", prefix);
|
||||||
sql.set_raw_config(key, Some(&self.imap.user)).await?;
|
sql.set_raw_config(key, Some(&self.imap.user)).await?;
|
||||||
@@ -273,7 +274,8 @@ impl LoginParam {
|
|||||||
sql.set_raw_config(key, Some(&self.smtp.server)).await?;
|
sql.set_raw_config(key, Some(&self.smtp.server)).await?;
|
||||||
|
|
||||||
let key = format!("{}send_port", prefix);
|
let key = format!("{}send_port", prefix);
|
||||||
sql.set_raw_config_int(key, self.smtp.port as i32).await?;
|
sql.set_raw_config_int(key, i32::from(self.smtp.port))
|
||||||
|
.await?;
|
||||||
|
|
||||||
let key = format!("{}send_user", prefix);
|
let key = format!("{}send_user", prefix);
|
||||||
sql.set_raw_config(key, Some(&self.smtp.user)).await?;
|
sql.set_raw_config(key, Some(&self.smtp.user)).await?;
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ impl rusqlite::types::ToSql for MsgId {
|
|||||||
format_err!("Invalid MsgId {}", self.0).into(),
|
format_err!("Invalid MsgId {}", self.0).into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let val = rusqlite::types::Value::Integer(self.0 as i64);
|
let val = rusqlite::types::Value::Integer(i64::from(self.0));
|
||||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ impl rusqlite::types::FromSql for MsgId {
|
|||||||
fn column_result(value: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult<Self> {
|
fn column_result(value: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult<Self> {
|
||||||
// Would be nice if we could use match here, but alas.
|
// Would be nice if we could use match here, but alas.
|
||||||
i64::column_result(value).and_then(|val| {
|
i64::column_result(value).and_then(|val| {
|
||||||
if 0 <= val && val <= std::u32::MAX as i64 {
|
if 0 <= val && val <= i64::from(std::u32::MAX) {
|
||||||
Ok(MsgId::new(val as u32))
|
Ok(MsgId::new(val as u32))
|
||||||
} else {
|
} else {
|
||||||
Err(rusqlite::types::FromSqlError::OutOfRange(val))
|
Err(rusqlite::types::FromSqlError::OutOfRange(val))
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ impl StatusUpdateId {
|
|||||||
|
|
||||||
impl rusqlite::types::ToSql for StatusUpdateId {
|
impl rusqlite::types::ToSql for StatusUpdateId {
|
||||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
||||||
let val = rusqlite::types::Value::Integer(self.0 as i64);
|
let val = rusqlite::types::Value::Integer(i64::from(self.0));
|
||||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user