chore: Clippy fixes

This commit is contained in:
Ginger
2026-04-13 18:31:16 -04:00
parent 02f69a7160
commit a8a8e1ea51
25 changed files with 50 additions and 51 deletions
+1
View File
@@ -38,6 +38,7 @@ pub(super) fn dispatch(services: Arc<Services>, command: CommandInput) -> Proces
}
#[tracing::instrument(skip_all, name = "admin", level = "info")]
#[allow(clippy::result_large_err)]
async fn handle_command(services: Arc<Services>, command: CommandInput) -> ProcessorResult {
AssertUnwindSafe(Box::pin(process_command(services, &command)))
.catch_unwind()
+3 -3
View File
@@ -806,7 +806,7 @@ pub(super) async fn put_room_tag(
.account_data
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
tags_event
.content
@@ -843,7 +843,7 @@ pub(super) async fn delete_room_tag(
.account_data
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
tags_event.content.tags.remove(&tag.clone().into());
@@ -873,7 +873,7 @@ pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId)
.account_data
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
.await
+1 -1
View File
@@ -24,7 +24,7 @@ pub(crate) async fn list_rooms(
.iter_ids()
.filter_map(|room_id| async move {
if !services.rooms.metadata.is_banned(&room_id).await {
Some(room_id.to_owned())
Some(room_id.clone())
} else {
None
}
+2 -2
View File
@@ -173,8 +173,8 @@ pub(crate) async fn change_password_route(
.get_pusher_device(&pushkey)
.await
.ok()
.filter(|pusher_device| pusher_device != body.sender_device())
.is_some()
.as_ref()
.is_some_and(|pusher_device| pusher_device != body.sender_device())
.then_some(pushkey)
})
.for_each(async |pushkey| {
+1 -1
View File
@@ -314,7 +314,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.collect()
.await;
all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members));
all_rooms.sort_by_key(|r| std::cmp::Reverse(r.num_joined_members));
let total_room_count_estimate = UInt::try_from(all_rooms.len())
.unwrap_or_else(|_| uint!(0))
+1 -1
View File
@@ -431,7 +431,7 @@ where
add_unsigned_device_display_name(&mut keys, metadata, include_display_names)
.map_err(|_| err!(Database("invalid device keys in database")))?;
container.insert(device_id.to_owned(), keys);
container.insert(device_id.clone(), keys);
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ pub(crate) async fn ban_user_route(
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
content.membership = MembershipState::Ban;
content.reason = body.reason.clone();
content.reason.clone_from(&body.reason);
content.displayname = None;
content.avatar_url = None;
content.is_direct = None;
+5 -3
View File
@@ -426,7 +426,9 @@ async fn join_room_by_id_helper_remote(
join_content.avatar_url = services.users.avatar_url(sender_user).await.ok();
join_content.blurhash = services.users.blurhash(sender_user).await.ok();
join_content.reason = reason;
join_content.join_authorized_via_users_server = join_authorized_via_users_server.clone();
join_content
.join_authorized_via_users_server
.clone_from(&join_authorized_via_users_server);
join_event_stub.insert(
"content".to_owned(),
@@ -752,7 +754,7 @@ async fn join_room_by_id_helper_local(
content.displayname = services.users.displayname(sender_user).await.ok();
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
content.blurhash = services.users.blurhash(sender_user).await.ok();
content.reason = reason.clone();
content.reason.clone_from(&reason);
content.join_authorized_via_users_server = auth_user;
// Try normal join first
@@ -861,7 +863,7 @@ async fn make_join_request(
);
return Err(e);
},
| ErrorKind::Forbidden { .. } => {
| ErrorKind::Forbidden => {
warn!("{remote_server} refuses to let us join: {e}.");
return Err(e);
},
+1 -1
View File
@@ -39,7 +39,7 @@ pub(crate) async fn kick_user_route(
}
event.membership = MembershipState::Leave;
event.reason = body.reason.clone();
event.reason.clone_from(&body.reason);
event.is_direct = None;
event.join_authorized_via_users_server = None;
event.third_party_invite = None;
+1 -1
View File
@@ -347,7 +347,7 @@ async fn knock_room_helper_local(
content.displayname = services.users.displayname(sender_user).await.ok();
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
content.blurhash = services.users.blurhash(sender_user).await.ok();
content.reason = reason.clone();
content.reason.clone_from(&reason.clone());
// Try normal knock first
let Err(error) = services
+1 -1
View File
@@ -119,5 +119,5 @@ fn membership_filter<Pdu: Event>(
return None;
}
return Some(pdu);
Some(pdu)
}
+1 -1
View File
@@ -35,7 +35,7 @@ pub(crate) async fn unban_user_route(
}
current_member_content.membership = MembershipState::Leave;
current_member_content.reason = body.reason.clone();
current_member_content.reason.clone_from(&body.reason);
current_member_content.join_authorized_via_users_server = None;
current_member_content.third_party_invite = None;
current_member_content.is_direct = None;
+7 -7
View File
@@ -36,7 +36,7 @@ pub(crate) async fn get_profile_route(
return Err!(Request(NotFound("This user's profile could not be fetched.")));
};
Ok(get_profile::v3::Response::from_iter(profile.into_iter()))
Ok(get_profile::v3::Response::from_iter(profile))
}
pub(crate) async fn get_profile_field_route(
@@ -115,7 +115,7 @@ async fn fetch_full_profile(
services.users.clear_profile(user_id).await;
for (field, value) in response.iter() {
let Ok(value) = ProfileFieldValue::new(&field, value.to_owned()) else {
let Ok(value) = ProfileFieldValue::new(field, value.to_owned()) else {
// Skip malformed fields
continue;
};
@@ -123,7 +123,7 @@ async fn fetch_full_profile(
set_profile_field(services, user_id, ProfileFieldChange::Set(value)).await;
}
Some(BTreeMap::from_iter(response.into_iter()))
Some(BTreeMap::from_iter(response))
}
async fn fetch_profile_field(
@@ -192,7 +192,7 @@ pub(crate) async fn get_local_profile(
profile.insert(key, value);
}
return profile;
profile
}
pub(crate) async fn get_local_profile_field(
@@ -238,13 +238,13 @@ enum ProfileFieldChange {
impl ProfileFieldChange {
fn field_name(&self) -> ProfileFieldName {
match self {
| &ProfileFieldChange::Delete(ref name) => name.clone(),
| &ProfileFieldChange::Set(ref value) => value.field_name(),
| &Self::Delete(ref name) => name.clone(),
| &Self::Set(ref value) => value.field_name(),
}
}
fn value(&self) -> Option<Value> {
if let &ProfileFieldChange::Set(ref value) = self {
if let Self::Set(value) = self {
Some(value.value().into_owned())
} else {
None
+4 -4
View File
@@ -238,8 +238,8 @@ pub(crate) async fn create_room_route(
.as_object()
.unwrap()
.get("origin_server_ts")
.and_then(|value| value.as_integer())
.map(|value| value.into())
.and_then(ruma::CanonicalJsonValue::as_integer)
.map(Into::into)
.and_then(|value: i64| value.try_into().ok())
.map(MilliSecondsSinceUnixEpoch);
@@ -266,7 +266,7 @@ pub(crate) async fn create_room_route(
| None => {
let as_room_id = create_event_id.as_str().replace('$', "!");
trace!("Creating room with v12 room ID {as_room_id}");
RoomId::parse(&as_room_id)?.to_owned()
RoomId::parse(&as_room_id)?.clone()
},
};
drop(state_lock);
@@ -342,7 +342,7 @@ pub(crate) async fn create_room_route(
let power_levels_content = default_power_levels_content(
body.power_level_content_override
.as_ref()
.map(|power_levels| power_levels.cast_ref()),
.map(Raw::cast_ref),
&body.visibility,
power_levels_to_grant,
creators,
+1 -1
View File
@@ -90,7 +90,7 @@ pub(crate) async fn room_initial_sync_route(
Ok(assign!(Response::new(room_id.to_owned()), {
account_data: vec![],
state: state.into(),
state: state,
messages: messages.chunk.is_empty().or_some(messages),
visibility: visibility.into(),
membership,
+1 -1
View File
@@ -50,7 +50,7 @@ pub(crate) async fn search_events_route(
if let Some(criteria) = &body.search_categories.room_events {
result_categories.room_events =
category_room_events(&services, sender_user, next_batch, criteria).await?
category_room_events(&services, sender_user, next_batch, criteria).await?;
}
Ok(Response::new(result_categories))
+2 -2
View File
@@ -170,7 +170,8 @@ pub(crate) async fn handle_login(
debug!("Got password login type");
let user_id_or_localpart = match (identifier, user) {
| (Some(UserIdentifier::Matrix(MatrixUserIdentifier { user, .. })), _) => user,
| (Some(UserIdentifier::Matrix(MatrixUserIdentifier { user, .. })), _)
| (None, Some(user)) => user,
| (Some(UserIdentifier::Email(EmailUserIdentifier { address, .. })), _) => {
let email = Address::try_from(address.to_owned())
.map_err(|_| err!(Request(InvalidParam("Email is malformed"))))?;
@@ -181,7 +182,6 @@ pub(crate) async fn handle_login(
.await
.ok_or_else(|| err!(Request(Forbidden("Invalid identifier or password"))))?
},
| (None, Some(user)) => user,
| _ => {
return Err!(Request(InvalidParam("Identifier type not recognized")));
},
+3 -3
View File
@@ -941,13 +941,13 @@ where
)
.await
{
device_list_changes.insert(user_id.to_owned());
device_list_changes.insert(user_id.clone());
}
},
| MembershipState::Leave => {
// Write down users that have left encrypted rooms we
// are in
left_encrypted_users.insert(user_id.to_owned());
left_encrypted_users.insert(user_id.clone());
},
| _ => {},
}
@@ -968,7 +968,7 @@ where
// already
.filter_map(async |user_id| {
share_encrypted_room(services, sender_user, &user_id, Some(room_id))
.map(|res| res.or_some(user_id.to_owned()))
.map(|res| res.or_some(user_id.clone()))
.await
})
.collect::<Vec<_>>()
+3 -3
View File
@@ -27,7 +27,7 @@ pub(crate) async fn update_tag_route(
.account_data
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
tags_event
.content
@@ -62,7 +62,7 @@ pub(crate) async fn delete_tag_route(
.account_data
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
tags_event.content.tags.remove(&body.tag.clone().into());
@@ -94,7 +94,7 @@ pub(crate) async fn get_tags_route(
.account_data
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
.await
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
Ok(get_tags::v3::Response::new(tags_event.content.tags))
}
+1 -1
View File
@@ -99,7 +99,7 @@ pub(crate) async fn send_event_to_device_route(
event_type,
event.clone(),
)
.await
.await;
})
.await;
},
+5 -5
View File
@@ -36,7 +36,7 @@ pub(super) trait CheckAuth: AuthScheme {
async move {
let route = TypeId::of::<R>();
let output = Self::extract_authentication(&incoming_request).map_err(|err| {
let output = Self::extract_authentication(incoming_request).map_err(|err| {
err!(Request(Unauthorized(warn!(
"Failed to extract authorization: {}",
err.into()
@@ -85,8 +85,8 @@ impl CheckAuth for ServerSignatures {
let keys: PubKeyMap = [(output.origin.as_str().into(), keys)].into();
match output.verify_request(request, destination, &keys) {
| Ok(_) => Ok(Auth {
origin: Some(output.origin.to_owned()),
| Ok(()) => Ok(Auth {
origin: Some(output.origin.clone()),
..Default::default()
}),
| Err(err) =>
@@ -123,11 +123,11 @@ impl CheckAuth for AccessToken {
}
}
return Ok(Auth {
Ok(Auth {
sender_user: Some(sender_user),
sender_device: Some(sender_device),
..Default::default()
});
})
}
}
+1 -1
View File
@@ -155,7 +155,7 @@ pub(crate) async fn create_invite_route(
if let Err(e) = services
.antispam
.user_may_invite(sender_user.to_owned(), recipient_user.clone(), body.room_id.clone())
.user_may_invite(sender_user.clone(), recipient_user.clone(), body.room_id.clone())
.await
{
warn!("Antispam rejected invite: {e:?}");
+1 -1
View File
@@ -56,7 +56,7 @@ pub(crate) async fn get_server_keys_route(
}
fn valid_until_ts() -> MilliSecondsSinceUnixEpoch {
let dur = Duration::from_secs(86400 * 7);
let dur = Duration::from_hours(168);
let timepoint = timepoint_from_now(dur).expect("SystemTime should not overflow");
MilliSecondsSinceUnixEpoch::from_system_time(timepoint).expect("UInt should not overflow")
}
+1 -1
View File
@@ -744,7 +744,7 @@ async fn handle_edu_direct_to_device_event(
ev_type,
event.clone(),
)
.await
.await;
})
.await;
},
+1 -5
View File
@@ -212,11 +212,7 @@ impl Service {
root_summary.inaccessible_children.into_iter().collect();
// TODO refactor this with Vec::peek_mut once it's stabilized
loop {
let Some(layer) = queue.last_mut() else {
break;
};
while let Some(layer) = queue.last_mut() {
let Some(SpaceChild { room_id, via }) = layer.pop() else {
// If this layer is empty, discard it from the queue and continue
queue.pop();