diff --git a/Cargo.toml b/Cargo.toml index dd4cf60c..8e816675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ unnested_or_patterns = "warn" unreadable_literal = "warn" unseparated_literal_suffix = "warn" unused_async = "warn" +unused_self = "warn" verbose_file_reads = "warn" wildcard_dependencies = "warn" diff --git a/src/service/admin.rs b/src/service/admin.rs index 1a7cd8aa..3d10be63 100644 --- a/src/service/admin.rs +++ b/src/service/admin.rs @@ -277,12 +277,12 @@ impl Service { let command_line = lines.next().expect("each string has at least one line"); let body: Vec<_> = lines.collect(); - let admin_command = match self.parse_admin_command(command_line) { + let admin_command = match Self::parse_admin_command(command_line) { Ok(command) => command, Err(error) => { let server_name = services().globals.server_name(); let message = error.replace("server.name", server_name.as_str()); - let html_message = self.usage_to_html(&message, server_name); + let html_message = Self::usage_to_html(&message, server_name); return RoomMessageEventContent::text_html(message, html_message); } @@ -306,7 +306,7 @@ impl Service { } // Parse chat messages from the admin room into an AdminCommand object - fn parse_admin_command(&self, command_line: &str) -> std::result::Result { + fn parse_admin_command(command_line: &str) -> std::result::Result { // Note: argv[0] is `@grapevine:servername:`, which is treated as the main command let mut argv: Vec<_> = command_line.split_whitespace().collect(); @@ -864,7 +864,7 @@ impl Service { } // Utility to turn clap's `--help` text to HTML. - fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String { + fn usage_to_html(text: &str, server_name: &ServerName) -> String { // Replace `@grapevine:servername:-subcmdname` with `@grapevine:servername: subcmdname` let text = text.replace( &format!("@grapevine:{server_name}:-"), @@ -1183,6 +1183,8 @@ impl Service { /// Gets the room ID of the admin room /// /// Errors are propagated from the database, and will have None if there is no admin room + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn get_admin_room(&self) -> Result> { let admin_room_alias: Box = format!("#admins:{}", services().globals.server_name()) diff --git a/src/service/media.rs b/src/service/media.rs index c19497cf..7b12ab1f 100644 --- a/src/service/media.rs +++ b/src/service/media.rs @@ -86,7 +86,7 @@ impl Service { /// Returns width, height of the thumbnail and whether it should be cropped. Returns None when /// the server should send the original file. - pub(crate) fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { + fn thumbnail_properties(width: u32, height: u32) -> Option<(u32, u32, bool)> { match (width, height) { (0..=32, 0..=32) => Some((32, 32, true)), (0..=96, 0..=96) => Some((96, 96, true)), @@ -113,9 +113,8 @@ impl Service { width: u32, height: u32, ) -> Result> { - let (width, height, crop) = self - .thumbnail_properties(width, height) - .unwrap_or((0, 0, false)); // 0, 0 because that's the original file + let (width, height, crop) = + Self::thumbnail_properties(width, height).unwrap_or((0, 0, false)); // 0, 0 because that's the original file if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc.clone(), width, height) diff --git a/src/service/rooms/event_handler.rs b/src/service/rooms/event_handler.rs index f86465ed..9e6b4802 100644 --- a/src/service/rooms/event_handler.rs +++ b/src/service/rooms/event_handler.rs @@ -132,7 +132,7 @@ impl Service { pub_key_map, ) .await?; - self.check_room_id(room_id, &incoming_pdu)?; + Self::check_room_id(room_id, &incoming_pdu)?; // 8. if not timeline event: stop if !is_timeline_event { @@ -375,7 +375,7 @@ impl Service { ) .map_err(|_| Error::bad_database("Event is not a valid PDU."))?; - self.check_room_id(room_id, &incoming_pdu)?; + Self::check_room_id(room_id, &incoming_pdu)?; if !auth_events_known { // 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events @@ -411,7 +411,7 @@ impl Service { continue; }; - self.check_room_id(room_id, &auth_event)?; + Self::check_room_id(room_id, &auth_event)?; match auth_events.entry(( auth_event.kind.to_string().into(), @@ -1287,7 +1287,7 @@ impl Service { .await .pop() { - self.check_room_id(room_id, &pdu)?; + Self::check_room_id(room_id, &pdu)?; if amount > services().globals.max_fetch_prev_events() { // Max limit reached @@ -1612,6 +1612,8 @@ impl Service { } /// Returns Ok if the acl allows the server + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { let Some(acl_event) = services().rooms.state_accessor.room_state_get( room_id, @@ -1815,7 +1817,7 @@ impl Service { )) } - fn check_room_id(&self, room_id: &RoomId, pdu: &PduEvent) -> Result<()> { + fn check_room_id(room_id: &RoomId, pdu: &PduEvent) -> Result<()> { if pdu.room_id != room_id { warn!("Found event from room {} in room {}", pdu.room_id, room_id); return Err(Error::BadRequest( diff --git a/src/service/rooms/pdu_metadata.rs b/src/service/rooms/pdu_metadata.rs index e9060ae7..13f29663 100644 --- a/src/service/rooms/pdu_metadata.rs +++ b/src/service/rooms/pdu_metadata.rs @@ -40,7 +40,11 @@ impl Service { } } - #[allow(clippy::too_many_arguments)] + #[allow( + clippy::too_many_arguments, + // Allowed because this function uses `services()` + clippy::unused_self, + )] pub(crate) fn paginate_relations_with_filter( &self, sender_user: &UserId, diff --git a/src/service/rooms/spaces.rs b/src/service/rooms/spaces.rs index 0ffbbf9a..bd1f5702 100644 --- a/src/service/rooms/spaces.rs +++ b/src/service/rooms/spaces.rs @@ -415,7 +415,7 @@ impl Service { )); } - self.translate_joinrule(&join_rule)? + Self::translate_joinrule(&join_rule)? }, room_type: services() .rooms @@ -436,7 +436,7 @@ impl Service { }) } - fn translate_joinrule(&self, join_rule: &JoinRule) -> Result { + fn translate_joinrule(join_rule: &JoinRule) -> Result { match join_rule { JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite), JoinRule::Knock => Ok(SpaceRoomJoinRule::Knock), @@ -448,6 +448,8 @@ impl Service { } } + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] fn handle_simplified_join_rule( &self, join_rule: &SpaceRoomJoinRule, @@ -473,7 +475,7 @@ impl Service { room_id: &RoomId, ) -> Result { if self.handle_simplified_join_rule( - &self.translate_joinrule(join_rule)?, + &Self::translate_joinrule(join_rule)?, sender_user, room_id, )? { diff --git a/src/service/rooms/state_accessor.rs b/src/service/rooms/state_accessor.rs index 4ed4d43f..6c1dd527 100644 --- a/src/service/rooms/state_accessor.rs +++ b/src/service/rooms/state_accessor.rs @@ -282,10 +282,7 @@ impl Service { } pub(crate) fn get_name(&self, room_id: &RoomId) -> Result> { - services() - .rooms - .state_accessor - .room_state_get(room_id, &StateEventType::RoomName, "")? + self.room_state_get(room_id, &StateEventType::RoomName, "")? .map_or(Ok(None), |s| { serde_json::from_str(s.content.get()) .map(|c: RoomNameEventContent| Some(c.name)) @@ -300,16 +297,15 @@ impl Service { } pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result> { - services() - .rooms - .state_accessor - .room_state_get(room_id, &StateEventType::RoomAvatar, "")? + self.room_state_get(room_id, &StateEventType::RoomAvatar, "")? .map_or(Ok(JsOption::Undefined), |s| { serde_json::from_str(s.content.get()) .map_err(|_| Error::bad_database("Invalid room avatar event in database.")) }) } + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn user_can_invite( &self, room_id: &RoomId, @@ -340,10 +336,7 @@ impl Service { room_id: &RoomId, user_id: &UserId, ) -> Result> { - services() - .rooms - .state_accessor - .room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())? + self.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())? .map_or(Ok(None), |s| { serde_json::from_str(s.content.get()) .map_err(|_| Error::bad_database("Invalid room member event in database.")) diff --git a/src/service/rooms/state_compressor.rs b/src/service/rooms/state_compressor.rs index 8ba07634..8881c652 100644 --- a/src/service/rooms/state_compressor.rs +++ b/src/service/rooms/state_compressor.rs @@ -89,6 +89,8 @@ impl Service { } } + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn compress_state_event( &self, shortstatekey: u64, @@ -106,6 +108,8 @@ impl Service { } /// Returns shortstatekey, event id + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn parse_compressed_state_event( &self, compressed_event: &CompressedStateEvent, diff --git a/src/service/rooms/timeline.rs b/src/service/rooms/timeline.rs index cb5f3332..1c57369d 100644 --- a/src/service/rooms/timeline.rs +++ b/src/service/rooms/timeline.rs @@ -662,7 +662,7 @@ impl Service { // Our depth is the maximum depth of prev_events + 1 let depth = prev_events .iter() - .filter_map(|event_id| Some(services().rooms.timeline.get_pdu(event_id).ok()??.depth)) + .filter_map(|event_id| Some(self.get_pdu(event_id).ok()??.depth)) .max() .unwrap_or_else(|| uint!(0)) + uint!(1); diff --git a/src/service/users.rs b/src/service/users.rs index 2e52f478..53882040 100644 --- a/src/service/users.rs +++ b/src/service/users.rs @@ -260,6 +260,8 @@ impl Service { } /// Check if a user is an admin + // Allowed because this function uses `services()` + #[allow(clippy::unused_self)] pub(crate) fn is_admin(&self, user_id: &UserId) -> Result { let admin_room_alias_id = RoomAliasId::parse(format!("#admins:{}", services().globals.server_name()))