fix clippy::ref_option

fix needless borrow

fix clippy::nonminimal_bool
This commit is contained in:
Jason Volk 2024-10-27 00:30:30 +00:00
parent 5e6dbaa27f
commit 9787dfe77c
11 changed files with 24 additions and 30 deletions

View file

@ -772,6 +772,7 @@ unused-qualifications = "warn"
#unused-results = "warn" # TODO #unused-results = "warn" # TODO
## some sadness ## some sadness
elided_named_lifetimes = "allow" # TODO!
let_underscore_drop = "allow" let_underscore_drop = "allow"
missing_docs = "allow" missing_docs = "allow"
# cfgs cannot be limited to expected cfgs or their de facto non-transitive/opt-in use-case e.g. # cfgs cannot be limited to expected cfgs or their de facto non-transitive/opt-in use-case e.g.

View file

@ -23,7 +23,7 @@ pub(crate) async fn set_global_account_data_route(
set_account_data( set_account_data(
&services, &services,
None, None,
&body.sender_user, body.sender_user.as_ref(),
&body.event_type.to_string(), &body.event_type.to_string(),
body.data.json(), body.data.json(),
) )
@ -41,7 +41,7 @@ pub(crate) async fn set_room_account_data_route(
set_account_data( set_account_data(
&services, &services,
Some(&body.room_id), Some(&body.room_id),
&body.sender_user, body.sender_user.as_ref(),
&body.event_type.to_string(), &body.event_type.to_string(),
body.data.json(), body.data.json(),
) )
@ -89,7 +89,7 @@ pub(crate) async fn get_room_account_data_route(
} }
async fn set_account_data( async fn set_account_data(
services: &Services, room_id: Option<&RoomId>, sender_user: &Option<OwnedUserId>, event_type: &str, services: &Services, room_id: Option<&RoomId>, sender_user: Option<&OwnedUserId>, event_type: &str,
data: &RawJsonValue, data: &RawJsonValue,
) -> Result<()> { ) -> Result<()> {
let sender_user = sender_user.as_ref().expect("user is authenticated"); let sender_user = sender_user.as_ref().expect("user is authenticated");

View file

@ -101,7 +101,7 @@ pub(crate) async fn report_event_route(
&pdu.event_id, &pdu.event_id,
&body.room_id, &body.room_id,
sender_user, sender_user,
&body.reason, body.reason.as_ref(),
body.score, body.score,
&pdu, &pdu,
) )
@ -134,7 +134,7 @@ pub(crate) async fn report_event_route(
/// check if report reasoning is less than or equal to 750 characters /// check if report reasoning is less than or equal to 750 characters
/// check if reporting user is in the reporting room /// check if reporting user is in the reporting room
async fn is_event_report_valid( async fn is_event_report_valid(
services: &Services, event_id: &EventId, room_id: &RoomId, sender_user: &UserId, reason: &Option<String>, services: &Services, event_id: &EventId, room_id: &RoomId, sender_user: &UserId, reason: Option<&String>,
score: Option<ruma::Int>, pdu: &std::sync::Arc<PduEvent>, score: Option<ruma::Int>, pdu: &std::sync::Arc<PduEvent>,
) -> Result<()> { ) -> Result<()> {
debug_info!("Checking if report from user {sender_user} for event {event_id} in room {room_id} is valid"); debug_info!("Checking if report from user {sender_user} for event {event_id} in room {room_id} is valid");

View file

@ -126,8 +126,8 @@ pub(crate) async fn create_room_route(
.await; .await;
let state_lock = services.rooms.state.mutex.lock(&room_id).await; let state_lock = services.rooms.state.mutex.lock(&room_id).await;
let alias: Option<OwnedRoomAliasId> = if let Some(alias) = &body.room_alias_name { let alias: Option<OwnedRoomAliasId> = if let Some(alias) = body.room_alias_name.as_ref() {
Some(room_alias_check(&services, alias, &body.appservice_info).await?) Some(room_alias_check(&services, alias, body.appservice_info.as_ref()).await?)
} else { } else {
None None
}; };
@ -270,7 +270,7 @@ pub(crate) async fn create_room_route(
} }
let power_levels_content = let power_levels_content =
default_power_levels_content(&body.power_level_content_override, &body.visibility, users)?; default_power_levels_content(body.power_level_content_override.as_ref(), &body.visibility, users)?;
services services
.rooms .rooms
@ -814,7 +814,7 @@ pub(crate) async fn upgrade_room_route(
/// creates the power_levels_content for the PDU builder /// creates the power_levels_content for the PDU builder
fn default_power_levels_content( fn default_power_levels_content(
power_level_content_override: &Option<Raw<RoomPowerLevelsEventContent>>, visibility: &room::Visibility, power_level_content_override: Option<&Raw<RoomPowerLevelsEventContent>>, visibility: &room::Visibility,
users: BTreeMap<OwnedUserId, Int>, users: BTreeMap<OwnedUserId, Int>,
) -> Result<serde_json::Value> { ) -> Result<serde_json::Value> {
let mut power_levels_content = serde_json::to_value(RoomPowerLevelsEventContent { let mut power_levels_content = serde_json::to_value(RoomPowerLevelsEventContent {
@ -864,7 +864,7 @@ fn default_power_levels_content(
/// if a room is being created with a room alias, run our checks /// if a room is being created with a room alias, run our checks
async fn room_alias_check( async fn room_alias_check(
services: &Services, room_alias_name: &str, appservice_info: &Option<RegistrationInfo>, services: &Services, room_alias_name: &str, appservice_info: Option<&RegistrationInfo>,
) -> Result<OwnedRoomAliasId> { ) -> Result<OwnedRoomAliasId> {
// Basic checks on the room alias validity // Basic checks on the room alias validity
if room_alias_name.contains(':') { if room_alias_name.contains(':') {
@ -905,7 +905,7 @@ async fn room_alias_check(
return Err(Error::BadRequest(ErrorKind::RoomInUse, "Room alias already exists.")); return Err(Error::BadRequest(ErrorKind::RoomInUse, "Room alias already exists."));
} }
if let Some(ref info) = appservice_info { if let Some(info) = appservice_info {
if !info.aliases.is_match(full_room_alias.as_str()) { if !info.aliases.is_match(full_room_alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace.")); return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
} }

View file

@ -560,7 +560,7 @@ pub(crate) async fn sync_events_v4_route(
for (_, pdu) in timeline_pdus { for (_, pdu) in timeline_pdus {
let ts = MilliSecondsSinceUnixEpoch(pdu.origin_server_ts); let ts = MilliSecondsSinceUnixEpoch(pdu.origin_server_ts);
if DEFAULT_BUMP_TYPES.contains(pdu.event_type()) && !timestamp.is_some_and(|time| time > ts) { if DEFAULT_BUMP_TYPES.contains(pdu.event_type()) && timestamp.is_none_or(|time| time <= ts) {
timestamp = Some(ts); timestamp = Some(ts);
} }
} }

View file

@ -1,4 +1,5 @@
//! Extended external extensions to futures::TryFutureExt //! Extended external extensions to futures::TryFutureExt
#![allow(clippy::type_complexity)]
use futures::{ use futures::{
future::{MapOkOrElse, UnwrapOrElse}, future::{MapOkOrElse, UnwrapOrElse},

View file

@ -1,4 +1,5 @@
//! Synchronous combinator extensions to futures::Stream //! Synchronous combinator extensions to futures::Stream
#![allow(clippy::type_complexity)]
use futures::{ use futures::{
future::{ready, Ready}, future::{ready, Ready},

View file

@ -1,4 +1,5 @@
//! Synchronous combinator extensions to futures::TryStream //! Synchronous combinator extensions to futures::TryStream
#![allow(clippy::type_complexity)]
use futures::{ use futures::{
future::{ready, Ready}, future::{ready, Ready},

View file

@ -164,11 +164,11 @@ fn get_default(field: &Field) -> Option<String> {
continue; continue;
}; };
if !path if path
.segments .segments
.iter() .iter()
.next() .next()
.is_some_and(|s| s.ident == "serde") .is_none_or(|s| s.ident == "serde")
{ {
continue; continue;
} }
@ -218,12 +218,7 @@ fn get_doc_default(field: &Field) -> Option<String> {
continue; continue;
}; };
if !path if path.segments.iter().next().is_none_or(|s| s.ident == "doc") {
.segments
.iter()
.next()
.is_some_and(|s| s.ident == "doc")
{
continue; continue;
} }
@ -266,12 +261,7 @@ fn get_doc_comment(field: &Field) -> Option<String> {
continue; continue;
}; };
if !path if path.segments.iter().next().is_none_or(|s| s.ident == "doc") {
.segments
.iter()
.next()
.is_some_and(|s| s.ident == "doc")
{
continue; continue;
} }

View file

@ -370,9 +370,9 @@ impl Service {
/// Sets the self-reference to crate::Services which will provide context to /// Sets the self-reference to crate::Services which will provide context to
/// the admin commands. /// the admin commands.
pub(super) fn set_services(&self, services: &Option<Arc<crate::Services>>) { pub(super) fn set_services(&self, services: Option<&Arc<crate::Services>>) {
let receiver = &mut *self.services.services.write().expect("locked for writing"); let receiver = &mut *self.services.services.write().expect("locked for writing");
let weak = services.as_ref().map(Arc::downgrade); let weak = services.map(Arc::downgrade);
*receiver = weak; *receiver = weak;
} }
} }

View file

@ -113,7 +113,7 @@ impl Services {
pub async fn start(self: &Arc<Self>) -> Result<Arc<Self>> { pub async fn start(self: &Arc<Self>) -> Result<Arc<Self>> {
debug_info!("Starting services..."); debug_info!("Starting services...");
self.admin.set_services(&Some(Arc::clone(self))); self.admin.set_services(Some(Arc::clone(self)).as_ref());
globals::migrations::migrations(self).await?; globals::migrations::migrations(self).await?;
self.manager self.manager
.lock() .lock()
@ -151,7 +151,7 @@ impl Services {
manager.stop().await; manager.stop().await;
} }
self.admin.set_services(&None); self.admin.set_services(None);
debug_info!("Services shutdown complete."); debug_info!("Services shutdown complete.");
} }