From a68528479f4efd7ae8fb26843141e5ec5579eea0 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sat, 5 Sep 2020 00:21:19 +0300 Subject: [PATCH] Remove dead code markers --- src/constants.rs | 27 ++++----------------------- src/headerdef.rs | 1 - src/message.rs | 5 ++--- src/peerstate.rs | 8 -------- tests/stress.rs | 17 +++++------------ 5 files changed, 11 insertions(+), 47 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index f8747e6de..7cb9130fb 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,6 +1,4 @@ //! # Constants -#![allow(dead_code)] - use deltachat_derive::*; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; @@ -9,13 +7,6 @@ lazy_static! { pub static ref DC_VERSION_STR: String = env!("CARGO_PKG_VERSION").to_string(); } -// some defaults -const DC_E2EE_DEFAULT_ENABLED: i32 = 1; -const DC_INBOX_WATCH_DEFAULT: i32 = 1; -const DC_SENTBOX_WATCH_DEFAULT: i32 = 1; -const DC_MVBOX_WATCH_DEFAULT: i32 = 1; -const DC_MVBOX_MOVE_DEFAULT: i32 = 1; - #[derive( Debug, Display, @@ -118,11 +109,11 @@ pub const DC_GCL_ADD_SELF: usize = 0x02; pub const DC_RESEND_USER_AVATAR_DAYS: i64 = 14; /// virtual chat showing all messages belonging to chats flagged with chats.blocked=2 -pub(crate) const DC_CHAT_ID_DEADDROP: u32 = 1; +pub const DC_CHAT_ID_DEADDROP: u32 = 1; /// messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) pub const DC_CHAT_ID_TRASH: u32 = 3; /// a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be sent and shown) -const DC_CHAT_ID_MSGS_IN_CREATION: u32 = 4; +pub const DC_CHAT_ID_MSGS_IN_CREATION: u32 = 4; /// virtual chat showing all messages flagged with msgs.starred=2 pub const DC_CHAT_ID_STARRED: u32 = 5; /// only an indicator in a chatlist @@ -166,9 +157,9 @@ pub const DC_MSG_ID_DAYMARKER: u32 = 9; pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9; /// approx. max. length returned by dc_msg_get_text() -const DC_MAX_GET_TEXT_LEN: usize = 30000; +pub const DC_MAX_GET_TEXT_LEN: usize = 30000; /// approx. max. length returned by dc_get_msg_info() -const DC_MAX_GET_INFO_LEN: usize = 100_000; +pub const DC_MAX_GET_INFO_LEN: usize = 100_000; pub const DC_CONTACT_ID_UNDEFINED: u32 = 0; pub const DC_CONTACT_ID_SELF: u32 = 1; @@ -295,16 +286,6 @@ mod tests { } } -// These constants are used as events -// reported to the callback given to dc_context_new(). -// If you do not want to handle an event, it is always safe to return 0, -// so there is no need to add a "case" for every event. - -const DC_EVENT_FILE_COPIED: usize = 2055; // deprecated; -const DC_EVENT_IS_OFFLINE: usize = 2081; // deprecated; -const DC_ERROR_SEE_STRING: usize = 0; // deprecated; -const DC_ERROR_SELF_NOT_IN_GROUP: usize = 1; // deprecated; - pub const DC_JOB_DELETE_MSG_ON_IMAP: i32 = 110; #[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] diff --git a/src/headerdef.rs b/src/headerdef.rs index 5743351e6..cadb300aa 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -3,7 +3,6 @@ use mailparse::{MailHeader, MailHeaderMap}; #[derive(Debug, Display, Clone, PartialEq, Eq, EnumVariantNames, AsStaticStr)] #[strum(serialize_all = "kebab_case")] -#[allow(dead_code)] pub enum HeaderDef { MessageId, Subject, diff --git a/src/message.rs b/src/message.rs index b87aee441..8e0232cfb 100644 --- a/src/message.rs +++ b/src/message.rs @@ -494,7 +494,7 @@ impl Message { pub fn get_text(&self) -> Option { self.text .as_ref() - .map(|text| dc_truncate(text, 30000).to_string()) + .map(|text| dc_truncate(text, DC_MAX_GET_TEXT_LEN).to_string()) } pub fn get_filename(&self) -> Option { @@ -969,7 +969,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String { return ret; } let rawtxt = rawtxt.unwrap_or_default(); - let rawtxt = dc_truncate(rawtxt.trim(), 100_000); + let rawtxt = dc_truncate(rawtxt.trim(), DC_MAX_GET_INFO_LEN); let fts = dc_timestamp_to_str(msg.get_timestamp()); ret += &format!("Sent: {}", fts); @@ -1797,7 +1797,6 @@ pub async fn update_server_uid( } } -#[allow(dead_code)] pub async fn dc_empty_server(context: &Context, flags: u32) { job::kill_action(context, Action::EmptyServer).await; job::add( diff --git a/src/peerstate.rs b/src/peerstate.rs index 4f9b31589..3462c495d 100644 --- a/src/peerstate.rs +++ b/src/peerstate.rs @@ -490,7 +490,6 @@ mod tests { use super::*; use crate::test_utils::*; use pretty_assertions::assert_eq; - use tempfile::TempDir; #[async_std::test] async fn test_peerstate_save_to_db() { @@ -636,11 +635,4 @@ mod tests { assert_eq!(peerstate.gossip_key_fingerprint, None); assert_eq!(peerstate.verified_key_fingerprint, None); } - - // TODO: don't copy this from stress.rs - #[allow(dead_code)] - struct TestContext { - ctx: Context, - dir: TempDir, - } } diff --git a/tests/stress.rs b/tests/stress.rs index 09ab1924e..f52f9a47c 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -2,7 +2,7 @@ use deltachat::config; use deltachat::context::*; -use tempfile::{tempdir, TempDir}; +use tempfile::tempdir; /* some data used for testing ******************************************************************************/ @@ -92,26 +92,19 @@ async fn stress_functions(context: &Context) { // free(qr.cast()); } -#[allow(dead_code)] -struct TestContext { - ctx: Context, - dir: TempDir, -} - -async fn create_test_context() -> TestContext { +async fn create_test_context() -> Context { use rand::Rng; let dir = tempdir().unwrap(); let dbfile = dir.path().join("db.sqlite"); let id = rand::thread_rng().gen(); - let ctx = Context::new("FakeOs".into(), dbfile.into(), id) + Context::new("FakeOs".into(), dbfile.into(), id) .await - .unwrap(); - TestContext { ctx, dir } + .unwrap() } #[async_std::test] async fn test_stress_tests() { let context = create_test_context().await; - stress_functions(&context.ctx).await; + stress_functions(&context).await; }