Enable more lints and apply their suggestions

This commit is contained in:
Jonas Platte 2021-10-13 10:24:39 +02:00
parent 09895a20c8
commit 1c4d9af586
No known key found for this signature in database
GPG key ID: 7D261D771D915378
13 changed files with 47 additions and 40 deletions

View file

@ -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"),

View file

@ -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::<HashSet<_>>();
let statediffremoved = parent_stateinfo
.1
.difference(&current_state)
.cloned()
.copied()
.collect::<HashSet<_>>();
(statediffnew, statediffremoved)

View file

@ -22,7 +22,7 @@ pub trait Tree: Send + Sync {
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
fn insert_batch<'a>(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
fn insert_batch(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
fn remove(&self, key: &[u8]) -> Result<()>;
@ -35,7 +35,7 @@ pub trait Tree: Send + Sync {
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
fn increment_batch<'a>(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>;
fn increment_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>;
fn scan_prefix<'a>(
&'a self,

View file

@ -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<Option<String>> {

View file

@ -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<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,

View file

@ -50,7 +50,7 @@ pub type StateHashId = Vec<u8>;
pub type CompressedStateEvent = [u8; 2 * size_of::<u64>()];
pub struct Rooms {
pub edus: edus::RoomEdus,
pub edus: RoomEdus,
pub(super) pduid_pdu: Arc<dyn Tree>, // PduId = ShortRoomId + Count
pub(super) eventid_pduid: Arc<dyn Tree>,
pub(super) roomid_pduleaves: Arc<dyn Tree>,
@ -371,13 +371,13 @@ impl Rooms {
{
let statediffnew = new_state_ids_compressed
.difference(&parent_stateinfo.1)
.cloned()
.copied()
.collect::<HashSet<_>>();
let statediffremoved = parent_stateinfo
.1
.difference(&new_state_ids_compressed)
.cloned()
.copied()
.collect::<HashSet<_>>();
(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::<HashSet<_>>();
let statediffremoved = parent_stateinfo
.1
.difference(&state_ids_compressed)
.cloned()
.copied()
.collect::<HashSet<_>>();
(statediffnew, statediffremoved)

View file

@ -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?

View file

@ -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)]

View file

@ -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)]

View file

@ -257,7 +257,7 @@ impl PduEvent {
mut json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> {
json.insert(
"event_id".to_string(),
"event_id".to_owned(),
CanonicalJsonValue::String(event_id.as_str().to_owned()),
);

View file

@ -344,7 +344,7 @@ impl<T: Outgoing> Deref for Ruma<T> {
}
/// This struct converts ruma responses into rocket http responses.
pub type ConduitResult<T> = std::result::Result<RumaResponse<T>, Error>;
pub type ConduitResult<T> = Result<RumaResponse<T>, Error>;
pub fn response<T: OutgoingResponse>(response: RumaResponse<T>) -> response::Result<'static> {
let http_response = response

View file

@ -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::<SocketAddr>() {
FedDest::Literal(addr)
} else if let Ok(addr) = hostname.parse::<IpAddr>() {
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::<PduEvent>(
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::<PduEvent>, // 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::<Vec<u64>>();
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);

View file

@ -123,7 +123,7 @@ pub fn deserialize_from_str<
E: std::fmt::Display,
>(
deserializer: D,
) -> std::result::Result<T, D::Error> {
) -> Result<T, D::Error> {
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);
impl<'de, T: FromStr<Err = Err>, Err: std::fmt::Display> serde::de::Visitor<'de>
for Visitor<T, Err>