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
## some sadness
elided_named_lifetimes = "allow" # TODO!
let_underscore_drop = "allow"
missing_docs = "allow"
# 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(
&services,
None,
&body.sender_user,
body.sender_user.as_ref(),
&body.event_type.to_string(),
body.data.json(),
)
@ -41,7 +41,7 @@ pub(crate) async fn set_room_account_data_route(
set_account_data(
&services,
Some(&body.room_id),
&body.sender_user,
body.sender_user.as_ref(),
&body.event_type.to_string(),
body.data.json(),
)
@ -89,7 +89,7 @@ pub(crate) async fn get_room_account_data_route(
}
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,
) -> Result<()> {
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,
&body.room_id,
sender_user,
&body.reason,
body.reason.as_ref(),
body.score,
&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 reporting user is in the reporting room
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>,
) -> Result<()> {
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;
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
let alias: Option<OwnedRoomAliasId> = if let Some(alias) = &body.room_alias_name {
Some(room_alias_check(&services, alias, &body.appservice_info).await?)
let alias: Option<OwnedRoomAliasId> = if let Some(alias) = body.room_alias_name.as_ref() {
Some(room_alias_check(&services, alias, body.appservice_info.as_ref()).await?)
} else {
None
};
@ -270,7 +270,7 @@ pub(crate) async fn create_room_route(
}
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
.rooms
@ -814,7 +814,7 @@ pub(crate) async fn upgrade_room_route(
/// creates the power_levels_content for the PDU builder
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>,
) -> Result<serde_json::Value> {
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
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> {
// Basic checks on the room alias validity
if room_alias_name.contains(':') {
@ -905,7 +905,7 @@ async fn room_alias_check(
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()) {
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 {
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);
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -370,9 +370,9 @@ impl Service {
/// Sets the self-reference to crate::Services which will provide context to
/// 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 weak = services.as_ref().map(Arc::downgrade);
let weak = services.map(Arc::downgrade);
*receiver = weak;
}
}

View file

@ -113,7 +113,7 @@ impl Services {
pub async fn start(self: &Arc<Self>) -> Result<Arc<Self>> {
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?;
self.manager
.lock()
@ -151,7 +151,7 @@ impl Services {
manager.stop().await;
}
self.admin.set_services(&None);
self.admin.set_services(None);
debug_info!("Services shutdown complete.");
}