Fix rustc / clippy warnings

This commit is contained in:
Jonas Platte 2022-01-20 00:10:39 +01:00
parent a0fc5eba72
commit 756a41f22d
No known key found for this signature in database
GPG key ID: 7D261D771D915378
8 changed files with 46 additions and 54 deletions

View file

@ -3,8 +3,7 @@ use ruma::{
api::client::{error::ErrorKind, r0::context::get_context},
events::EventType,
};
use std::collections::HashSet;
use std::convert::TryFrom;
use std::{collections::HashSet, convert::TryFrom};
#[cfg(feature = "conduit_bin")]
use rocket::get;
@ -55,8 +54,8 @@ pub async fn get_context_route(
))?;
if !db.rooms.lazy_load_was_sent_before(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
&base_event.sender,
)? {
@ -79,8 +78,8 @@ pub async fn get_context_route(
for (_, event) in &events_before {
if !db.rooms.lazy_load_was_sent_before(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
&event.sender,
)? {
@ -112,8 +111,8 @@ pub async fn get_context_route(
for (_, event) in &events_after {
if !db.rooms.lazy_load_was_sent_before(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
&event.sender,
)? {

View file

@ -272,7 +272,7 @@ pub async fn get_key_changes_route(
device_list_updates.extend(
db.users
.keys_changed(
&sender_user.to_string(),
sender_user.as_str(),
body.from
.parse()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?,

View file

@ -139,7 +139,7 @@ pub async fn get_message_events_route(
let to = body.to.as_ref().map(|t| t.parse());
db.rooms
.lazy_load_confirm_delivery(&sender_user, &sender_device, &body.room_id, from)?;
.lazy_load_confirm_delivery(sender_user, sender_device, &body.room_id, from)?;
// Use limit or else 10
let limit = body.limit.try_into().map_or(10_usize, |l: u32| l as usize);
@ -168,8 +168,8 @@ pub async fn get_message_events_route(
for (_, event) in &events_after {
if !db.rooms.lazy_load_was_sent_before(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
&event.sender,
)? {
@ -205,8 +205,8 @@ pub async fn get_message_events_route(
for (_, event) in &events_before {
if !db.rooms.lazy_load_was_sent_before(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
&event.sender,
)? {
@ -239,8 +239,8 @@ pub async fn get_message_events_route(
if let Some(next_token) = next_token {
db.rooms.lazy_load_mark_sent(
&sender_user,
&sender_device,
sender_user,
sender_device,
&body.room_id,
lazy_loaded,
next_token,

View file

@ -52,7 +52,7 @@ pub async fn set_displayname_route(
.room_state_get(
&room_id,
&EventType::RoomMember,
&sender_user.to_string(),
sender_user.as_str(),
)?
.ok_or_else(|| {
Error::bad_database(
@ -195,7 +195,7 @@ pub async fn set_avatar_url_route(
.room_state_get(
&room_id,
&EventType::RoomMember,
&sender_user.to_string(),
sender_user.as_str(),
)?
.ok_or_else(|| {
Error::bad_database(

View file

@ -212,28 +212,22 @@ impl Database {
return Ok(());
}
if sled_exists {
if config.database_backend != "sled" {
return Err(Error::bad_config(
"Found sled at database_path, but is not specified in config.",
));
}
if sled_exists && config.database_backend != "sled" {
return Err(Error::bad_config(
"Found sled at database_path, but is not specified in config.",
));
}
if sqlite_exists {
if config.database_backend != "sqlite" {
return Err(Error::bad_config(
"Found sqlite at database_path, but is not specified in config.",
));
}
if sqlite_exists && config.database_backend != "sqlite" {
return Err(Error::bad_config(
"Found sqlite at database_path, but is not specified in config.",
));
}
if rocksdb_exists {
if config.database_backend != "rocksdb" {
return Err(Error::bad_config(
"Found rocksdb at database_path, but is not specified in config.",
));
}
if rocksdb_exists && config.database_backend != "rocksdb" {
return Err(Error::bad_config(
"Found rocksdb at database_path, but is not specified in config.",
));
}
Ok(())

View file

@ -118,7 +118,7 @@ impl Admin {
if let Ok(response) = guard._db.memory_usage() {
send_message(RoomMessageEventContent::text_plain(response), guard, &state_lock);
} else {
send_message(RoomMessageEventContent::text_plain("Failed to get database memory usage.".to_string()), guard, &state_lock);
send_message(RoomMessageEventContent::text_plain("Failed to get database memory usage.".to_owned()), guard, &state_lock);
}
}
AdminCommand::SendMessage(message) => {

View file

@ -2727,7 +2727,7 @@ impl Rooms {
let state_lock = mutex_state.lock().await;
let mut event: RoomMemberEventContent = serde_json::from_str(
self.room_state_get(room_id, &EventType::RoomMember, &user_id.to_string())?
self.room_state_get(room_id, &EventType::RoomMember, user_id.as_str())?
.ok_or(Error::BadRequest(
ErrorKind::BadState,
"Cannot leave a room you are not a member of.",
@ -3462,8 +3462,7 @@ impl Rooms {
&key[0].to_be_bytes(),
&chain
.iter()
.map(|s| s.to_be_bytes().to_vec())
.flatten()
.flat_map(|s| s.to_be_bytes().to_vec())
.collect::<Vec<u8>>(),
)?;
}
@ -3484,11 +3483,11 @@ impl Rooms {
) -> Result<bool> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(&device_id.as_bytes());
key.extend_from_slice(device_id.as_bytes());
key.push(0xff);
key.extend_from_slice(&room_id.as_bytes());
key.extend_from_slice(room_id.as_bytes());
key.push(0xff);
key.extend_from_slice(&ll_user.as_bytes());
key.extend_from_slice(ll_user.as_bytes());
Ok(self.lazyloadedids.get(&key)?.is_some())
}
@ -3528,14 +3527,14 @@ impl Rooms {
)) {
let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff);
prefix.extend_from_slice(&device_id.as_bytes());
prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff);
prefix.extend_from_slice(&room_id.as_bytes());
prefix.extend_from_slice(room_id.as_bytes());
prefix.push(0xff);
for ll_id in user_ids {
let mut key = prefix.clone();
key.extend_from_slice(&ll_id.as_bytes());
key.extend_from_slice(ll_id.as_bytes());
self.lazyloadedids.insert(&key, &[])?;
}
}
@ -3546,15 +3545,15 @@ impl Rooms {
#[tracing::instrument(skip(self))]
pub fn lazy_load_reset(
&self,
user_id: &Box<UserId>,
device_id: &Box<DeviceId>,
room_id: &Box<RoomId>,
user_id: &UserId,
device_id: &DeviceId,
room_id: &RoomId,
) -> Result<()> {
let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff);
prefix.extend_from_slice(&device_id.as_bytes());
prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff);
prefix.extend_from_slice(&room_id.as_bytes());
prefix.extend_from_slice(room_id.as_bytes());
prefix.push(0xff);
for (key, _) in self.lazyloadedids.scan_prefix(prefix) {

View file

@ -1938,7 +1938,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
match handle_outlier_pdu(
origin,
create_event,
&next_id,
next_id,
room_id,
value.clone(),
db,
@ -2358,7 +2358,7 @@ pub fn get_event_route(
let room_id = <&RoomId>::try_from(room_id_str)
.map_err(|_| Error::bad_database("Invalid room id field in event in database"))?;
if !db.rooms.server_in_room(sender_servername, &room_id)? {
if !db.rooms.server_in_room(sender_servername, room_id)? {
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"Server is not in room",
@ -2821,7 +2821,7 @@ async fn create_join_event(
));
}
acl_check(sender_servername, room_id, &db)?;
acl_check(sender_servername, room_id, db)?;
// We need to return the state prior to joining, let's keep a reference to that here
let shortstatehash = db