From 26489910921d362b8d0a1f69f9974ee0a58e07d4 Mon Sep 17 00:00:00 2001 From: Olivia Lee Date: Sun, 20 Jul 2025 13:55:06 -0700 Subject: [PATCH] fix lints revealed by tracing change changes #[instrument] so that several lints that were previously hidden on instrumented functions are now visible. --- src/api/client_server/media.rs | 4 ++-- src/api/client_server/membership.rs | 4 ++-- src/api/client_server/sync/v3.rs | 1 + src/api/server_server.rs | 3 ++- src/service/pdu.rs | 36 ++++------------------------- src/service/pusher.rs | 2 ++ src/service/rooms/auth_chain.rs | 2 ++ src/service/rooms/event_handler.rs | 3 +++ src/service/rooms/state.rs | 6 ++++- src/service/rooms/state_accessor.rs | 2 ++ src/service/rooms/state_cache.rs | 8 ++++++- src/service/rooms/timeline.rs | 6 +++-- 12 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index ca9dda86..f7ffa413 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -320,7 +320,7 @@ async fn get_remote_content_via_legacy_api( } #[tracing::instrument] -pub(crate) async fn get_remote_content( +async fn get_remote_content( mxc: &MxcData<'_>, ) -> Result { let fed_result = get_remote_content_via_federation_api(mxc).await; @@ -785,7 +785,7 @@ async fn get_remote_thumbnail_via_legacy_api( } #[tracing::instrument] -pub(crate) async fn get_remote_thumbnail( +async fn get_remote_thumbnail( server_name: &ruma::ServerName, request: authenticated_media_fed::get_content_thumbnail::v1::Request, ) -> Result { diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 21a75be9..20c48cf4 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -1521,7 +1521,7 @@ pub(crate) async fn leave_room( services().rooms.state_cache.update_membership( room_id, user_id, - MembershipState::Leave, + &MembershipState::Leave, user_id, None, true, @@ -1575,7 +1575,7 @@ pub(crate) async fn leave_room( services().rooms.state_cache.update_membership( room_id, user_id, - MembershipState::Leave, + &MembershipState::Leave, user_id, last_state, true, diff --git a/src/api/client_server/sync/v3.rs b/src/api/client_server/sync/v3.rs index 9ac70a73..3108ff9c 100644 --- a/src/api/client_server/sync/v3.rs +++ b/src/api/client_server/sync/v3.rs @@ -915,6 +915,7 @@ async fn load_joined_room( }) } +#[allow(clippy::too_many_lines)] #[tracing::instrument(skip_all)] async fn collect_left_rooms( ctx: &SyncContext<'_>, diff --git a/src/api/server_server.rs b/src/api/server_server.rs index abd111f4..793cbbd2 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -147,6 +147,7 @@ pub(crate) enum AllowLoopbackRequests { No, } +#[allow(clippy::too_many_lines)] #[tracing::instrument(skip(request, log_error, allow_loopback), fields(url))] pub(crate) async fn send_request( destination: &ServerName, @@ -1883,7 +1884,7 @@ pub(crate) async fn create_invite_route( services().rooms.state_cache.update_membership( &body.room_id, &invited_user, - MembershipState::Invite, + &MembershipState::Invite, &sender, Some(invite_state), true, diff --git a/src/service/pdu.rs b/src/service/pdu.rs index fe13f1d2..3df17326 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -4,10 +4,9 @@ use ruma::{ canonical_json::redact_content_in_place, events::{ room::member::RoomMemberEventContent, - space::child::HierarchySpaceChildEvent, AnyEphemeralRoomEvent, - AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, - AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, - TimelineEventType, + space::child::HierarchySpaceChildEvent, AnyMessageLikeEvent, + AnyStateEvent, AnyStrippedStateEvent, AnySyncStateEvent, + AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, TimelineEventType, }, serde::Raw, state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, @@ -60,7 +59,7 @@ impl PduEvent { #[tracing::instrument(skip(self))] pub(crate) fn redact( &mut self, - room_version_id: RoomVersionId, + room_version_id: &RoomVersionId, reason: &PduEvent, ) -> crate::Result<()> { self.unsigned = None; @@ -71,7 +70,7 @@ impl PduEvent { })?; redact_content_in_place( &mut content, - &room_version_id, + room_version_id, self.kind.to_string(), ) .map_err(|e| { @@ -222,31 +221,6 @@ impl PduEvent { serde_json::from_value(json).expect("Raw::from_value always works") } - /// This only works for events that are also AnyRoomEvents. - #[tracing::instrument(skip(self))] - pub(crate) fn to_any_event(&self) -> Raw { - let mut json = json!({ - "content": self.content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "room_id": self.room_id, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - if let Some(state_key) = &self.state_key { - json["state_key"] = json!(state_key); - } - if let Some(redacts) = &self.redacts { - json["redacts"] = json!(redacts); - } - - serde_json::from_value(json).expect("Raw::from_value always works") - } - #[tracing::instrument(skip(self))] pub(crate) fn to_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); diff --git a/src/service/pusher.rs b/src/service/pusher.rs index 1b5d375d..8f58cea8 100644 --- a/src/service/pusher.rs +++ b/src/service/pusher.rs @@ -210,6 +210,8 @@ impl Service { Ok(()) } + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self, user, ruleset, pdu))] pub(crate) fn get_actions<'a>( &self, diff --git a/src/service/rooms/auth_chain.rs b/src/service/rooms/auth_chain.rs index 6711263d..2c7a4787 100644 --- a/src/service/rooms/auth_chain.rs +++ b/src/service/rooms/auth_chain.rs @@ -182,6 +182,8 @@ impl Service { })) } + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self))] fn get_auth_chain_inner( &self, diff --git a/src/service/rooms/event_handler.rs b/src/service/rooms/event_handler.rs index 96e33f5f..07eed506 100644 --- a/src/service/rooms/event_handler.rs +++ b/src/service/rooms/event_handler.rs @@ -82,6 +82,7 @@ impl Service { /// 13. Use state resolution to find new room state /// 14. Check if the event passes auth based on the "current state" of the /// room, if not soft fail it + #[allow(clippy::too_many_lines)] #[tracing::instrument(skip(self, value, is_timeline_event, pub_key_map))] pub(crate) async fn handle_incoming_pdu<'a>( &self, @@ -535,6 +536,7 @@ impl Service { }) } + #[allow(clippy::too_many_lines)] #[tracing::instrument(skip_all, fields( incoming_pdu = %incoming_pdu.event_id, ))] @@ -1869,6 +1871,7 @@ impl Service { /// Search the DB for the signing keys of the given server, if we don't have /// them fetch them from the server and save to our DB. + #[allow(clippy::too_many_lines)] #[tracing::instrument( skip(self, signature_ids), fields(signature_ids = debug_slice_truncated(&signature_ids, 3)) diff --git a/src/service/rooms/state.rs b/src/service/rooms/state.rs index bf028f71..e692251d 100644 --- a/src/service/rooms/state.rs +++ b/src/service/rooms/state.rs @@ -142,7 +142,7 @@ impl Service { services().rooms.state_cache.update_membership( room_id, &user_id, - membership, + &membership, &pdu.sender, None, false, @@ -319,6 +319,8 @@ impl Service { /// Gather events to help the invited user identify the room /// /// Also includes the invite event itself. + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self, invite_event))] pub(crate) fn get_helpful_invite_events( &self, @@ -365,6 +367,8 @@ impl Service { } /// Returns the value of a field of an `m.room.create` event's `content`. + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self))] pub(crate) fn get_create_content( &self, diff --git a/src/service/rooms/state_accessor.rs b/src/service/rooms/state_accessor.rs index e9794e53..3c859a01 100644 --- a/src/service/rooms/state_accessor.rs +++ b/src/service/rooms/state_accessor.rs @@ -140,6 +140,8 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, /// `state_key`). + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self))] pub(crate) fn state_get_id( &self, diff --git a/src/service/rooms/state_cache.rs b/src/service/rooms/state_cache.rs index 3e9608a3..1bf0fdbc 100644 --- a/src/service/rooms/state_cache.rs +++ b/src/service/rooms/state_cache.rs @@ -47,12 +47,14 @@ impl Service { } /// Update current membership data. + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] #[tracing::instrument(skip(self, last_state))] pub(crate) fn update_membership( &self, room_id: &RoomId, user_id: &UserId, - membership: MembershipState, + membership: &MembershipState, sender: &UserId, last_state: Option>>, update_joined_count: bool, @@ -404,6 +406,8 @@ impl Service { } /// Returns an iterator over all invited members of a room. + // Unused, but needed for consistency with other methods + #[allow(dead_code)] #[tracing::instrument(skip(self))] pub(crate) fn room_members_invited<'a>( &'a self, @@ -504,6 +508,8 @@ impl Service { self.db.is_invited(user_id, room_id) } + // Unused, but needed for consistency with other methods + #[allow(dead_code)] #[tracing::instrument(skip(self))] pub(crate) fn is_left( &self, diff --git a/src/service/rooms/timeline.rs b/src/service/rooms/timeline.rs index 10fabf40..8ee8669b 100644 --- a/src/service/rooms/timeline.rs +++ b/src/service/rooms/timeline.rs @@ -277,6 +277,7 @@ impl Service { /// happens in `append_pdu`. /// /// Returns pdu id + #[allow(clippy::too_many_lines)] #[tracing::instrument(skip(self, pdu, pdu_json, leaves))] pub(crate) async fn append_pdu( &self, @@ -572,7 +573,7 @@ impl Service { services().rooms.state_cache.update_membership( &pdu.room_id, &target_user_id, - membership, + &membership, &pdu.sender, invite_state, true, @@ -937,6 +938,7 @@ impl Service { /// Creates a new persisted data unit and adds it to a room. This function /// takes a roomid_mutex_state, meaning that only this function is able /// to mutate the room state. + #[allow(clippy::too_many_lines)] #[tracing::instrument(skip(self))] pub(crate) async fn build_and_append_pdu( &self, @@ -1259,7 +1261,7 @@ impl Service { .rooms .state .get_create_content::(&pdu.room_id)?; - pdu.redact(room_version_id, reason)?; + pdu.redact(&room_version_id, reason)?; self.replace_pdu( &pdu_id,