From b7d6fa056296bb7e307e4f06fa87d8122b5acbea Mon Sep 17 00:00:00 2001 From: Rudi Floren Date: Mon, 22 Feb 2021 17:24:19 +0000 Subject: [PATCH 01/15] Make clippy happy (needless-return) --- src/database/rooms.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 7e80134..9b22fd9 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -183,7 +183,7 @@ impl Rooms { ))) }) } else { - return Ok(None); + Ok(None) } } From 85b8f1b7cbd9d458adadd2dc3fc4d22929142799 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:45:27 +0100 Subject: [PATCH 02/15] Fix clippy::single_char_pattern --- src/appservice_server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appservice_server.rs b/src/appservice_server.rs index 986909b..04f14c0 100644 --- a/src/appservice_server.rs +++ b/src/appservice_server.rs @@ -25,7 +25,7 @@ where let mut parts = http_request.uri().clone().into_parts(); let old_path_and_query = parts.path_and_query.unwrap().as_str().to_owned(); - let symbol = if old_path_and_query.contains("?") { + let symbol = if old_path_and_query.contains('?') { "&" } else { "?" From 54a080fe1fa06bb8dcb2f2feed804d2b46147bdc Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:45:46 +0100 Subject: [PATCH 03/15] Fix clippy::useless_conversion --- src/client_server/push.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client_server/push.rs b/src/client_server/push.rs index 03da73a..5403f96 100644 --- a/src/client_server/push.rs +++ b/src/client_server/push.rs @@ -95,7 +95,7 @@ pub async fn get_pushrule_route( if let Some(rule) = rule { Ok(get_pushrule::Response { rule }.into()) } else { - Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.").into()) + Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")) } } From 256383800994d5c510b6f0c9dec983ffc88c3a92 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:46:06 +0100 Subject: [PATCH 04/15] Fix clippy::search_is_some --- src/client_server/session.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client_server/session.rs b/src/client_server/session.rs index 8c8b643..7b3acfc 100644 --- a/src/client_server/session.rs +++ b/src/client_server/session.rs @@ -119,8 +119,7 @@ pub async fn login_route( let device_exists = body.device_id.as_ref().map_or(false, |device_id| { db.users .all_device_ids(&user_id) - .find(|x| x.as_ref().map_or(false, |v| v == device_id)) - .is_some() + .any(|x| x.as_ref().map_or(false, |v| v == device_id)) }); if device_exists { From 11830f6e1a8047e32692283f2d058a459fdb68cc Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:46:23 +0100 Subject: [PATCH 05/15] Fix clippy::type_complexity --- src/database/globals.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/database/globals.rs b/src/database/globals.rs index ccd6284..7a0c217 100644 --- a/src/database/globals.rs +++ b/src/database/globals.rs @@ -9,9 +9,10 @@ use trust_dns_resolver::TokioAsyncResolver; pub const COUNTER: &str = "c"; +type WellKnownMap = HashMap, (String, Option)>; #[derive(Clone)] pub struct Globals { - pub actual_destination_cache: Arc, (String, Option)>>>, // actual_destination, host + pub actual_destination_cache: Arc>, // actual_destination, host pub(super) globals: sled::Tree, config: Config, keypair: Arc, From 386b79fcf8c9bf9cfcb4bf054bf46982d8db0cd4 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:51:26 +0100 Subject: [PATCH 06/15] Fix clippy::redundant_closure --- src/database/rooms.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 9b22fd9..b05785d 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -970,7 +970,7 @@ impl Rooms { .get("users") .and_then(|users| users.as_sequence()) .map_or_else( - || Vec::new(), + Vec::new, |users| { users .iter() From b2d543972b5407eb959eb4704b2570e3ba79c024 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:53:15 +0100 Subject: [PATCH 07/15] Circumvent clippy::too-many-arguments --- src/database/rooms.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/database/rooms.rs b/src/database/rooms.rs index b05785d..ec28418 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -449,6 +449,7 @@ impl Rooms { /// /// By this point the incoming event should be fully authenticated, no auth happens /// in `append_pdu`. + #[allow(clippy::too_many_arguments)] pub fn append_pdu( &self, pdu: &PduEvent, From 0cc9d1be376c9db680c998f8e27fcd83b9281cb1 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 19:55:06 +0100 Subject: [PATCH 08/15] Circumvent clippy::blocks_in_if_conditions --- src/database/rooms.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/rooms.rs b/src/database/rooms.rs index ec28418..6ee4f19 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -1003,7 +1003,7 @@ impl Rooms { .and_then(|string| { UserId::parse_with_server_name(string, globals.server_name()).ok() }); - + #[allow(clippy::blocks_in_if_conditions)] if bridge_user_id.map_or(false, |bridge_user_id| { self.is_joined(&bridge_user_id, room_id).unwrap_or(false) }) || users.iter().any(|users| { From d78c870e51d9f3a47d864aa4471107b29c386583 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:44:36 +0100 Subject: [PATCH 09/15] Fix clippy::string-lit-as-bytes --- src/database/sending.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index 11034ea..ae6d206 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -102,7 +102,7 @@ impl Sending { match response { Ok((server, is_appservice)) => { let mut prefix = if is_appservice { - "+".as_bytes().to_vec() + b"+".to_vec() } else { Vec::new() }; @@ -148,7 +148,7 @@ impl Sending { Err((server, is_appservice, e)) => { info!("Couldn't send transaction to {}\n{}", server, e); let mut prefix = if is_appservice { - "+".as_bytes().to_vec() + b"+".to_vec() } else { Vec::new() }; From d3b9288f38513115ad4d8640cbdfac03f30c9efe Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:44:51 +0100 Subject: [PATCH 10/15] Fix clippy::single-char-pattern --- src/database/sending.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index ae6d206..c038319 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -180,7 +180,7 @@ impl Sending { .map_err(|_| Error::bad_database("ServerName in servernamepduid bytes are invalid.")) .map(|server_str| { // Appservices start with a plus - if server_str.starts_with("+") { + if server_str.starts_with('+') { (server_str[1..].to_owned(), true) } else { (server_str, false) From 874821b035bd923f029770c9d1e9b7470228b143 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:46:03 +0100 Subject: [PATCH 11/15] Circumvent clippy::blocks_in_if_conditions --- src/database/sending.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/database/sending.rs b/src/database/sending.rs index c038319..145c116 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -196,6 +196,7 @@ impl Sending { .map(|pdu_id| (server, is_appservice, pdu_id)) ) .filter(|(server, is_appservice, _)| { + #[allow(clippy::blocks_in_if_conditions)] if last_failed_try.get(server).map_or(false, |(tries, instant)| { // Fail if a request has failed recently (exponential backoff) let mut min_elapsed_duration = Duration::from_secs(60) * *tries * *tries; From f3b60386d78a4151b9e5994a70f978b11c198f2a Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:47:39 +0100 Subject: [PATCH 12/15] Fix clippy::string-lit-as-bytes --- src/database/sending.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index 145c116..056c37c 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -210,7 +210,7 @@ impl Sending { } let mut prefix = if *is_appservice { - "+".as_bytes().to_vec() + b"+".to_vec() } else { Vec::new() }; @@ -248,7 +248,7 @@ impl Sending { #[tracing::instrument(skip(self))] pub fn send_pdu_appservice(&self, appservice_id: &str, pdu_id: &[u8]) -> Result<()> { - let mut key = "+".as_bytes().to_vec(); + let mut key = b"+".to_vec(); key.extend_from_slice(appservice_id.as_bytes()); key.push(0xff); key.extend_from_slice(pdu_id); From 61f8766736a216431a3fa6677a17436a1031ce56 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:48:23 +0100 Subject: [PATCH 13/15] Fix clippy::single-char-pattern --- src/database/sending.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index 056c37c..48fe68a 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -386,7 +386,7 @@ impl Sending { })?; // Appservices start with a plus - let (server, is_appservice) = if server.starts_with("+") { + let (server, is_appservice) = if server.starts_with('+') { (&server[1..], true) } else { (&*server, false) From 86b2e1138c600c799538bc1c4f685d99e47f3b82 Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 21:51:11 +0100 Subject: [PATCH 14/15] Fix clippy::borrowed-box --- src/server_server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server_server.rs b/src/server_server.rs index 4ea9bfe..6d3cdf0 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -220,7 +220,7 @@ fn add_port_to_hostname(destination_str: String) -> String { #[tracing::instrument(skip(globals))] async fn find_actual_destination( globals: &crate::database::globals::Globals, - destination: &Box, + destination: &'_ ServerName, ) -> (String, Option) { let mut host = None; From ce4024c32126d082c2b81152784dd286bc789f9a Mon Sep 17 00:00:00 2001 From: Valkum Date: Mon, 22 Feb 2021 22:23:50 +0100 Subject: [PATCH 15/15] Fix clippy::needless-lifetimes --- src/server_server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server_server.rs b/src/server_server.rs index 6d3cdf0..261172a 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -277,9 +277,9 @@ async fn find_actual_destination( } #[tracing::instrument(skip(globals))] -async fn query_srv_record<'a>( +async fn query_srv_record( globals: &crate::database::globals::Globals, - hostname: &'a str, + hostname: &'_ str, ) -> Option { if let Ok(Some(host_port)) = globals .dns_resolver()