diff --git a/src/client_server/room.rs b/src/client_server/room.rs index d1c79dff..eb68135f 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -475,7 +475,7 @@ pub async fn upgrade_room_route( PduBuilder { event_type: EventType::RoomTombstone, content: to_raw_value(&RoomTombstoneEventContent { - body: "This room has been replaced".to_string(), + body: "This room has been replaced".to_owned(), replacement_room: replacement_room.clone(), }) .expect("event is valid, we just created it"), diff --git a/src/database.rs b/src/database.rs index 110d4d0c..63c4ebc4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -499,13 +499,13 @@ impl Database { if let Some(parent_stateinfo) = states_parents.last() { let statediffnew = current_state .difference(&parent_stateinfo.1) - .cloned() + .copied() .collect::>(); let statediffremoved = parent_stateinfo .1 .difference(¤t_state) - .cloned() + .copied() .collect::>(); (statediffnew, statediffremoved) diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index 5b941fbe..11bbc3b1 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -22,7 +22,7 @@ pub trait Tree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; - fn insert_batch<'a>(&self, iter: &mut dyn Iterator, Vec)>) -> Result<()>; + fn insert_batch(&self, iter: &mut dyn Iterator, Vec)>) -> Result<()>; fn remove(&self, key: &[u8]) -> Result<()>; @@ -35,7 +35,7 @@ pub trait Tree: Send + Sync { ) -> Box, Vec)> + 'a>; fn increment(&self, key: &[u8]) -> Result>; - fn increment_batch<'a>(&self, iter: &mut dyn Iterator>) -> Result<()>; + fn increment_batch(&self, iter: &mut dyn Iterator>) -> Result<()>; fn scan_prefix<'a>( &'a self, diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs index 27d8030d..a960c72f 100644 --- a/src/database/key_backups.rs +++ b/src/database/key_backups.rs @@ -81,7 +81,7 @@ impl KeyBackups { )?; self.backupid_etag .insert(&key, &globals.next_count()?.to_be_bytes())?; - Ok(version.to_string()) + Ok(version.to_owned()) } pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { diff --git a/src/database/proxy.rs b/src/database/proxy.rs index 78e9d2bf..33f7f3d9 100644 --- a/src/database/proxy.rs +++ b/src/database/proxy.rs @@ -136,7 +136,7 @@ impl std::str::FromStr for WildCardedDomain { }) } } -impl<'de> serde::de::Deserialize<'de> for WildCardedDomain { +impl<'de> Deserialize<'de> for WildCardedDomain { fn deserialize(deserializer: D) -> std::result::Result where D: serde::de::Deserializer<'de>, diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 3096150d..1912e0c8 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -50,7 +50,7 @@ pub type StateHashId = Vec; pub type CompressedStateEvent = [u8; 2 * size_of::()]; pub struct Rooms { - pub edus: edus::RoomEdus, + pub edus: RoomEdus, pub(super) pduid_pdu: Arc, // PduId = ShortRoomId + Count pub(super) eventid_pduid: Arc, pub(super) roomid_pduleaves: Arc, @@ -371,13 +371,13 @@ impl Rooms { { let statediffnew = new_state_ids_compressed .difference(&parent_stateinfo.1) - .cloned() + .copied() .collect::>(); let statediffremoved = parent_stateinfo .1 .difference(&new_state_ids_compressed) - .cloned() + .copied() .collect::>(); (statediffnew, statediffremoved) @@ -498,7 +498,7 @@ impl Rooms { if parent != 0_u64 { let mut response = self.load_shortstatehash_info(parent)?; let mut state = response.last().unwrap().1.clone(); - state.extend(added.iter().cloned()); + state.extend(added.iter().copied()); for r in &removed { state.remove(r); } @@ -1773,13 +1773,13 @@ impl Rooms { if let Some(parent_stateinfo) = states_parents.last() { let statediffnew = state_ids_compressed .difference(&parent_stateinfo.1) - .cloned() + .copied() .collect::>(); let statediffremoved = parent_stateinfo .1 .difference(&state_ids_compressed) - .cloned() + .copied() .collect::>(); (statediffnew, statediffremoved) diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index e0639ffd..26f22bf4 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -331,7 +331,7 @@ impl RoomEdus { &self, user_id: &UserId, room_id: &RoomId, - presence: ruma::events::presence::PresenceEvent, + presence: PresenceEvent, globals: &super::super::globals::Globals, ) -> Result<()> { // TODO: Remove old entry? Or maybe just wipe completely from time to time? diff --git a/src/lib.rs b/src/lib.rs index fbffb7e3..82b8f340 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,9 @@ +#![warn( + rust_2018_idioms, + unused_qualifications, + clippy::cloned_instead_of_copied, + clippy::str_to_string +)] #![allow(clippy::suspicious_else_formatting)] #![deny(clippy::dbg_macro)] diff --git a/src/main.rs b/src/main.rs index 06409eeb..84dfb1fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,9 @@ -#![warn(rust_2018_idioms)] +#![warn( + rust_2018_idioms, + unused_qualifications, + clippy::cloned_instead_of_copied, + clippy::str_to_string +)] #![allow(clippy::suspicious_else_formatting)] #![deny(clippy::dbg_macro)] diff --git a/src/pdu.rs b/src/pdu.rs index b74d079c..0a765e1f 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -257,7 +257,7 @@ impl PduEvent { mut json: CanonicalJsonObject, ) -> Result { json.insert( - "event_id".to_string(), + "event_id".to_owned(), CanonicalJsonValue::String(event_id.as_str().to_owned()), ); diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index 4629de92..03c115cd 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -344,7 +344,7 @@ impl Deref for Ruma { } /// This struct converts ruma responses into rocket http responses. -pub type ConduitResult = std::result::Result, Error>; +pub type ConduitResult = Result, Error>; pub fn response(response: RumaResponse) -> response::Result<'static> { let http_response = response diff --git a/src/server_server.rs b/src/server_server.rs index 805ae3a3..e9a94856 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -336,7 +336,7 @@ fn add_port_to_hostname(destination_str: &str) -> FedDest { None => (destination_str, ":8448"), Some(pos) => destination_str.split_at(pos), }; - FedDest::Named(host.to_string(), port.to_string()) + FedDest::Named(host.to_owned(), port.to_owned()) } /// Returns: actual_destination, host header @@ -358,7 +358,7 @@ async fn find_actual_destination( if let Some(pos) = destination_str.find(':') { // 2: Hostname with included port let (host, port) = destination_str.split_at(pos); - FedDest::Named(host.to_string(), port.to_string()) + FedDest::Named(host.to_owned(), port.to_owned()) } else { match request_well_known(globals, destination.as_str()).await { // 3: A .well-known file is available @@ -370,7 +370,7 @@ async fn find_actual_destination( if let Some(pos) = delegated_hostname.find(':') { // 3.2: Hostname with port in .well-known file let (host, port) = delegated_hostname.split_at(pos); - FedDest::Named(host.to_string(), port.to_string()) + FedDest::Named(host.to_owned(), port.to_owned()) } else { // Delegated hostname has no port in this branch if let Some(hostname_override) = @@ -454,12 +454,12 @@ async fn find_actual_destination( let hostname = if let Ok(addr) = hostname.parse::() { FedDest::Literal(addr) } else if let Ok(addr) = hostname.parse::() { - FedDest::Named(addr.to_string(), ":8448".to_string()) + FedDest::Named(addr.to_string(), ":8448".to_owned()) } else if let Some(pos) = hostname.find(':') { let (host, port) = hostname.split_at(pos); - FedDest::Named(host.to_string(), port.to_string()) + FedDest::Named(host.to_owned(), port.to_owned()) } else { - FedDest::Named(hostname, ":8448".to_string()) + FedDest::Named(hostname, ":8448".to_owned()) }; (actual_destination, hostname) } @@ -476,11 +476,7 @@ async fn query_srv_record( .map(|srv| { srv.iter().next().map(|result| { FedDest::Named( - result - .target() - .to_string() - .trim_end_matches('.') - .to_string(), + result.target().to_string().trim_end_matches('.').to_owned(), format!(":{}", result.port()), ) }) @@ -745,7 +741,7 @@ pub async fn send_transaction_message_route( Some(id) => id, None => { // Event is invalid - resolved_map.insert(event_id, Err("Event needs a valid RoomId.".to_string())); + resolved_map.insert(event_id, Err("Event needs a valid RoomId.".to_owned())); continue; } }; @@ -963,7 +959,7 @@ pub(crate) async fn handle_incoming_pdu<'a>( match db.rooms.exists(room_id) { Ok(true) => {} _ => { - return Err("Room is unknown to this server.".to_string()); + return Err("Room is unknown to this server.".to_owned()); } } @@ -1173,14 +1169,14 @@ fn handle_outlier_pdu<'a>( Err(e) => { // Drop warn!("Dropping bad event {}: {}", event_id, e); - return Err("Signature verification failed".to_string()); + return Err("Signature verification failed".to_owned()); } Ok(ruma::signatures::Verified::Signatures) => { // Redact warn!("Calculated hash does not match: {}", event_id); match ruma::signatures::redact(&value, room_version_id) { Ok(obj) => obj, - Err(_) => return Err("Redaction failed".to_string()), + Err(_) => return Err("Redaction failed".to_owned()), } } Ok(ruma::signatures::Verified::All) => value, @@ -1195,7 +1191,7 @@ fn handle_outlier_pdu<'a>( let incoming_pdu = serde_json::from_value::( serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"), ) - .map_err(|_| "Event is not a valid PDU.".to_string())?; + .map_err(|_| "Event is not a valid PDU.".to_owned())?; // 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events // 5. Reject "due to auth events" if can't get all the auth events or some of the auth events are also rejected "due to auth events" @@ -1280,9 +1276,9 @@ fn handle_outlier_pdu<'a>( None::, // TODO: third party invite |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) - .map_err(|_e| "Auth check failed".to_string())? + .map_err(|_e| "Auth check failed".to_owned())? { - return Err("Event has failed auth check with auth events.".to_string()); + return Err("Event has failed auth check with auth events.".to_owned()); } debug!("Validation successful."); @@ -2256,7 +2252,7 @@ pub(crate) fn get_auth_chain<'a>( .collect::>(); if let Some(cached) = db.rooms.get_auth_chain_from_cache(&chunk_key)? { hits += 1; - full_auth_chain.extend(cached.iter().cloned()); + full_auth_chain.extend(cached.iter().copied()); continue; } misses += 1; @@ -2267,7 +2263,7 @@ pub(crate) fn get_auth_chain<'a>( for (sevent_id, event_id) in chunk { if let Some(cached) = db.rooms.get_auth_chain_from_cache(&[sevent_id])? { hits2 += 1; - chunk_cache.extend(cached.iter().cloned()); + chunk_cache.extend(cached.iter().copied()); } else { misses2 += 1; let auth_chain = Arc::new(get_auth_chain_inner(room_id, &event_id, db)?); @@ -3385,10 +3381,10 @@ pub(crate) async fn fetch_join_signing_keys( // Try to fetch keys, failure is okay // Servers we couldn't find in the cache will be added to `servers` for pdu in &event.room_state.state { - let _ = get_server_keys_from_cache(&pdu, &mut servers, room_version, &mut pkm, db); + let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db); } for pdu in &event.room_state.auth_chain { - let _ = get_server_keys_from_cache(&pdu, &mut servers, room_version, &mut pkm, db); + let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db); } drop(pkm); diff --git a/src/utils.rs b/src/utils.rs index d21395e1..26d71a8c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -123,7 +123,7 @@ pub fn deserialize_from_str< E: std::fmt::Display, >( deserializer: D, -) -> std::result::Result { +) -> Result { struct Visitor, E>(std::marker::PhantomData); impl<'de, T: FromStr, Err: std::fmt::Display> serde::de::Visitor<'de> for Visitor