fix some more pedantic clippy lints

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-23 14:38:15 -04:00 committed by June
parent a7e6fe8b60
commit 7bd56765ef
22 changed files with 136 additions and 126 deletions

View file

@ -589,6 +589,7 @@ impl Service {
AdminCommand::try_parse_from(argv).map_err(|error| error.to_string())
}
#[allow(clippy::too_many_lines)]
async fn process_admin_command(&self, command: AdminCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
let reply_message_content = match command {
AdminCommand::Appservices(command) => match command {
@ -787,8 +788,8 @@ impl Service {
}
return Ok(RoomMessageEventContent::text_plain(format!(
"Deleted {} total MXCs from our database and the filesystem from event ID {event_id}.",
mxc_deletion_count
"Deleted {mxc_deletion_count} total MXCs from our database and the filesystem from \
event ID {event_id}."
)));
}
@ -1050,7 +1051,7 @@ impl Service {
if leave_rooms {
for &user_id in &user_ids {
let _ = leave_all_rooms(user_id).await;
_ = leave_all_rooms(user_id).await;
}
}
@ -1236,7 +1237,8 @@ impl Service {
evicting admins too)",
&local_user, &room_id
);
let _ = leave_room(&local_user, &room_id, None).await;
_ = leave_room(&local_user, &room_id, None).await;
}
} else {
for local_user in services()
@ -1364,7 +1366,7 @@ impl Service {
errors, evicting admins too)",
&local_user, room_id
);
let _ = leave_room(&local_user, room_id, None).await;
_ = leave_room(&local_user, room_id, None).await;
}
} else {
for local_user in services()
@ -1632,11 +1634,11 @@ impl Service {
(_, Ok(None)) => match services().rooms.alias.set_alias(&room_alias, &room_id) {
Ok(()) => RoomMessageEventContent::text_plain("Successfully set alias"),
Err(err) => {
RoomMessageEventContent::text_plain(format!("Failed to remove alias: {}", err))
RoomMessageEventContent::text_plain(format!("Failed to remove alias: {err}"))
},
},
(_, Err(err)) => {
RoomMessageEventContent::text_plain(format!("Unable to lookup alias: {}", err))
RoomMessageEventContent::text_plain(format!("Unable to lookup alias: {err}"))
},
},
RoomAliasCommand::Remove {
@ -1671,14 +1673,14 @@ impl Service {
},
RoomAliasCommand::List {
room_id,
} => match room_id {
Some(room_id) => {
} => {
if let Some(room_id) = room_id {
let aliases =
services().rooms.alias.local_aliases_for_room(&room_id).collect::<Result<Vec<_>, _>>();
match aliases {
Ok(aliases) => {
let plain_list = aliases.iter().fold(String::new(), |mut output, alias| {
writeln!(output, "- {}", alias).unwrap();
writeln!(output, "- {alias}").unwrap();
output
});
@ -1687,22 +1689,21 @@ impl Service {
output
});
let plain = format!("Aliases for {}:\n{}", room_id, plain_list);
let html = format!("Aliases for {}:\n<ul>{}</ul>", room_id, html_list);
let plain = format!("Aliases for {room_id}:\n{plain_list}");
let html = format!("Aliases for {room_id}:\n<ul>{html_list}</ul>");
RoomMessageEventContent::text_html(plain, html)
},
Err(err) => {
RoomMessageEventContent::text_plain(format!("Unable to list aliases: {}", err))
},
}
},
None => {
} else {
let aliases = services().rooms.alias.all_local_aliases().collect::<Result<Vec<_>, _>>();
match aliases {
Ok(aliases) => {
let server_name = services().globals.server_name();
let plain_list = aliases.iter().fold(String::new(), |mut output, (alias, id)| {
writeln!(output, "- `{}` -> #{}:{}", alias, id, server_name).unwrap();
writeln!(output, "- `{alias}` -> #{id}:{server_name}").unwrap();
output
});
@ -1718,15 +1719,15 @@ impl Service {
output
});
let plain = format!("Aliases:\n{}", plain_list);
let html = format!("Aliases:\n<ul>{}</ul>", html_list);
let plain = format!("Aliases:\n{plain_list}");
let html = format!("Aliases:\n<ul>{html_list}</ul>");
RoomMessageEventContent::text_html(plain, html)
},
Err(err) => {
RoomMessageEventContent::text_plain(format!("Unable to list room aliases: {}", err))
Err(e) => {
RoomMessageEventContent::text_plain(format!("Unable to list room aliases: {e}"))
},
}
},
}
},
},
RoomCommand::Directory(command) => match command {

View file

@ -106,11 +106,11 @@ impl RotationHandler {
let mut r = self.0.subscribe();
async move {
let _ = r.recv().await;
_ = r.recv().await;
}
}
pub fn fire(&self) { let _ = self.0.send(()); }
pub fn fire(&self) { _ = self.0.send(()); }
}
impl Default for RotationHandler {
@ -233,7 +233,7 @@ impl Client {
}
impl Service<'_> {
pub fn load(db: &'static dyn Data, config: Config) -> Result<Self> {
pub fn load(db: &'static dyn Data, config: &Config) -> Result<Self> {
let keypair = db.load_keypair();
let keypair = match keypair {
@ -282,7 +282,7 @@ impl Service<'_> {
})?,
actual_destination_cache: Arc::new(RwLock::new(WellKnownMap::new())),
tls_name_override: tls_name_override.clone(),
client: Client::new(&config, &tls_name_override),
client: Client::new(config, &tls_name_override),
jwt_decoding_key,
stable_room_versions,
unstable_room_versions,

View file

@ -52,7 +52,7 @@ impl Services<'_> {
+ sending::Data
+ 'static,
>(
db: &'static D, config: Config,
db: &'static D, config: &Config,
) -> Result<Self> {
Ok(Self {
appservice: appservice::Service::build(db)?,
@ -160,7 +160,7 @@ impl Services<'_> {
db,
url_preview_mutex: RwLock::new(HashMap::new()),
},
sending: sending::Service::build(db, &config),
sending: sending::Service::build(db, config),
globals: globals::Service::load(db, config)?,
})

View file

@ -18,7 +18,7 @@ impl Service {
pub async fn typing_add(&self, user_id: &UserId, room_id: &RoomId, timeout: u64) -> Result<()> {
self.typing.write().await.entry(room_id.to_owned()).or_default().insert(user_id.to_owned(), timeout);
self.last_typing_update.write().await.insert(room_id.to_owned(), services().globals.next_count()?);
let _ = self.typing_update_sender.send(room_id.to_owned());
_ = self.typing_update_sender.send(room_id.to_owned());
Ok(())
}
@ -26,7 +26,7 @@ impl Service {
pub async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> {
self.typing.write().await.entry(room_id.to_owned()).or_default().remove(user_id);
self.last_typing_update.write().await.insert(room_id.to_owned(), services().globals.next_count()?);
let _ = self.typing_update_sender.send(room_id.to_owned());
_ = self.typing_update_sender.send(room_id.to_owned());
Ok(())
}
@ -68,7 +68,7 @@ impl Service {
room.remove(&user);
}
self.last_typing_update.write().await.insert(room_id.to_owned(), services().globals.next_count()?);
let _ = self.typing_update_sender.send(room_id.to_owned());
_ = self.typing_update_sender.send(room_id.to_owned());
}
Ok(())

View file

@ -1143,7 +1143,7 @@ impl Service {
{
let mut server_key_ids = HashMap::new();
for event in events.into_iter() {
for event in events {
debug!("Fetching keys for event: {event:?}");
for (signature_server, signature) in event
.get("signatures")
@ -1391,10 +1391,10 @@ impl Service {
// 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 _ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm).await;
_ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm).await;
}
for pdu in &event.room_state.auth_chain {
let _ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm).await;
_ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm).await;
}
drop(pkm);

View file

@ -329,7 +329,7 @@ impl Service {
let mut children = Vec::new();
let mut inaccessible_children = Vec::new();
for child in get_parent_children(*room.clone(), suggested_only) {
for child in get_parent_children(&room.clone(), suggested_only) {
match self
.get_summary_and_children(&child, suggested_only, Identifier::ServerName(server_name))
.await?
@ -379,7 +379,7 @@ impl Service {
Ok(
if let Some(children_pdus) = get_stripped_space_child_events(current_room).await? {
let summary = self.get_room_summary(current_room, children_pdus, identifier);
let summary = self.get_room_summary(current_room, children_pdus, &identifier);
if let Ok(summary) = summary {
self.roomid_spacehierarchy_cache.lock().await.insert(
current_room.clone(),
@ -485,7 +485,7 @@ impl Service {
fn get_room_summary(
&self, current_room: &OwnedRoomId, children_state: Vec<Raw<HierarchySpaceChildEvent>>,
identifier: Identifier<'_>,
identifier: &Identifier<'_>,
) -> Result<SpaceHierarchyParentSummary, Error> {
let room_id: &RoomId = current_room;
@ -504,7 +504,7 @@ impl Service {
let allowed_room_ids = allowed_room_ids(join_rule.clone());
if !is_accessable_child(current_room, &join_rule.clone().into(), &identifier, &allowed_room_ids)? {
if !is_accessable_child(current_room, &join_rule.clone().into(), identifier, &allowed_room_ids)? {
debug!("User is not allowed to see room {room_id}");
// This error will be caught later
return Err(Error::BadRequest(ErrorKind::Forbidden, "User is not allowed to see the room"));
@ -590,7 +590,7 @@ impl Service {
let mut results = Vec::new();
let root = arena.first_untraversed().expect("The node just added is not traversed");
arena.push(root, get_parent_children(*summary.clone(), suggested_only));
arena.push(root, get_parent_children(&summary.clone(), suggested_only));
results.push(summary_to_chunk(*summary.clone()));
while let Some(current_room) = arena.first_untraversed() {
@ -603,7 +603,7 @@ impl Service {
)
.await?
{
let children = get_parent_children(*summary.clone(), suggested_only);
let children = get_parent_children(&summary.clone(), suggested_only);
arena.push(current_room, children);
if left_to_skip > 0 {
@ -837,7 +837,7 @@ fn allowed_room_ids(join_rule: JoinRule) -> Vec<OwnedRoomId> {
/// Returns the children of a SpaceHierarchyParentSummary, making use of the
/// children_state field
fn get_parent_children(parent: SpaceHierarchyParentSummary, suggested_only: bool) -> Vec<OwnedRoomId> {
fn get_parent_children(parent: &SpaceHierarchyParentSummary, suggested_only: bool) -> Vec<OwnedRoomId> {
parent
.children_state
.iter()
@ -861,10 +861,10 @@ mod tests {
use super::*;
fn first(arena: &mut Arena, room_id: OwnedRoomId) {
fn first(arena: &mut Arena, room_id: &OwnedRoomId) {
let first_untrav = arena.first_untraversed().unwrap();
assert_eq!(arena.get(first_untrav).unwrap().room_id, room_id);
assert_eq!(&arena.get(first_untrav).unwrap().room_id, room_id);
}
#[test]
@ -896,16 +896,16 @@ mod tests {
vec![owned_room_id!("!room1:example.org"), owned_room_id!("!room2:example.org")],
);
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!room2:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!room2:example.org"));
arena.push(
subspace2,
vec![owned_room_id!("!room3:example.org"), owned_room_id!("!room4:example.org")],
);
first(&mut arena, owned_room_id!("!room3:example.org"));
first(&mut arena, owned_room_id!("!room4:example.org"));
first(&mut arena, &owned_room_id!("!room3:example.org"));
first(&mut arena, &owned_room_id!("!room4:example.org"));
let foo_node = NodeId {
index: 1,
@ -931,7 +931,7 @@ mod tests {
let room1 = arena.first_untraversed().unwrap();
arena.push(room1, vec![]);
first(&mut arena, owned_room_id!("!room2:example.org"));
first(&mut arena, &owned_room_id!("!room2:example.org"));
assert!(arena.first_untraversed().is_none());
}
@ -973,9 +973,9 @@ mod tests {
],
);
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!room3:example.org"));
first(&mut arena, owned_room_id!("!room5:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!room3:example.org"));
first(&mut arena, &owned_room_id!("!room5:example.org"));
let subspace2 = arena.first_untraversed().unwrap();
@ -986,9 +986,9 @@ mod tests {
vec![owned_room_id!("!room1:example.org"), owned_room_id!("!room2:example.org")],
);
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!room2:example.org"));
first(&mut arena, owned_room_id!("!foo:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!room2:example.org"));
first(&mut arena, &owned_room_id!("!foo:example.org"));
assert_eq!(arena.first_untraversed(), None);
}
@ -1052,14 +1052,14 @@ mod tests {
.into();
assert_eq!(
get_parent_children(summary.clone(), false),
get_parent_children(&summary, false),
vec![
owned_room_id!("!foo:example.org"),
owned_room_id!("!bar:example.org"),
owned_room_id!("!baz:example.org")
]
);
assert_eq!(get_parent_children(summary, true), vec![owned_room_id!("!bar:example.org")]);
assert_eq!(get_parent_children(&summary, true), vec![owned_room_id!("!bar:example.org")]);
}
#[test]
@ -1191,10 +1191,10 @@ mod tests {
);
assert_eq!(arena.nodes.len(), 7);
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!room1:example.org"));
first(&mut arena, owned_room_id!("!subspace2:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!room1:example.org"));
first(&mut arena, &owned_room_id!("!subspace2:example.org"));
assert!(arena.first_untraversed().is_none());
}
}

View file

@ -409,7 +409,7 @@ impl Service {
}
#[tracing::instrument(skip(self, server, serialized))]
pub fn send_reliable_edu(&self, server: &ServerName, serialized: Vec<u8>, _id: u64) -> Result<()> {
pub fn send_reliable_edu(&self, server: &ServerName, serialized: Vec<u8>, id: u64) -> Result<()> {
let outgoing_kind = OutgoingKind::Normal(server.to_owned());
let event = SendingEventType::Edu(serialized);
let _cork = services().globals.db.cork()?;
@ -446,7 +446,7 @@ impl Service {
.map(OutgoingKind::Normal)
.collect::<Vec<_>>();
for outgoing_kind in requests.into_iter() {
for outgoing_kind in requests {
self.sender.send((outgoing_kind, SendingEventType::Flush, Vec::<u8>::new())).unwrap();
}