use/enable let_underscore_must_use lint

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-05-23 01:27:04 -04:00 committed by June 🍓🦴
parent 71bdcb958a
commit 32161801ed
15 changed files with 91 additions and 74 deletions

View file

@ -750,6 +750,7 @@ manual_let_else = "warn"
trivially_copy_pass_by_ref = "warn" trivially_copy_pass_by_ref = "warn"
wildcard_imports = "warn" wildcard_imports = "warn"
checked_conversions = "warn" checked_conversions = "warn"
let_underscore_must_use = "warn"
#integer_arithmetic = "warn" #integer_arithmetic = "warn"
#as_conversions = "warn" #as_conversions = "warn"
@ -767,7 +768,6 @@ mod_module_files = "allow"
unwrap_used = "allow" unwrap_used = "allow"
expect_used = "allow" expect_used = "allow"
if_then_some_else_none = "allow" if_then_some_else_none = "allow"
let_underscore_must_use = "allow"
let_underscore_future = "allow" let_underscore_future = "allow"
map_err_ignore = "allow" map_err_ignore = "allow"
missing_docs_in_private_items = "allow" missing_docs_in_private_items = "allow"

View file

@ -1,4 +1,4 @@
use std::fmt::Write as _; use std::fmt::Write;
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId}; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId};
@ -20,7 +20,8 @@ pub(crate) async fn incoming_federeation(_body: Vec<&str>) -> Result<RoomMessage
for (r, (e, i)) in map.iter() { for (r, (e, i)) in map.iter() {
let elapsed = i.elapsed(); let elapsed = i.elapsed();
let _ = writeln!(msg, "{} {}: {}m{}s", r, e, elapsed.as_secs() / 60, elapsed.as_secs() % 60); writeln!(msg, "{} {}: {}m{}s", r, e, elapsed.as_secs() / 60, elapsed.as_secs() % 60,)
.expect("should be able to write to string buffer");
} }
Ok(RoomMessageEventContent::text_plain(&msg)) Ok(RoomMessageEventContent::text_plain(&msg))
} }
@ -120,7 +121,7 @@ pub(crate) async fn remote_user_in_rooms(_body: Vec<&str>, user_id: Box<UserId>)
members, members,
escape_html(name) escape_html(name)
) )
.unwrap(); .expect("should be able to write to string buffer");
output output
}) })
); );

View file

@ -1,4 +1,4 @@
use std::fmt::Write as _; use std::fmt::Write;
use ruma::{events::room::message::RoomMessageEventContent, RoomAliasId}; use ruma::{events::room::message::RoomMessageEventContent, RoomAliasId};
@ -79,12 +79,13 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu
match aliases { match aliases {
Ok(aliases) => { Ok(aliases) => {
let plain_list = aliases.iter().fold(String::new(), |mut output, alias| { let plain_list = aliases.iter().fold(String::new(), |mut output, alias| {
writeln!(output, "- {alias}").unwrap(); writeln!(output, "- {alias}").expect("should be able to write to string buffer");
output output
}); });
let html_list = aliases.iter().fold(String::new(), |mut output, alias| { let html_list = aliases.iter().fold(String::new(), |mut output, alias| {
writeln!(output, "<li>{}</li>", escape_html(alias.as_ref())).unwrap(); writeln!(output, "<li>{}</li>", escape_html(alias.as_ref()))
.expect("should be able to write to string buffer");
output output
}); });
@ -106,7 +107,8 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu
let plain_list = aliases let plain_list = aliases
.iter() .iter()
.fold(String::new(), |mut output, (alias, id)| { .fold(String::new(), |mut output, (alias, id)| {
writeln!(output, "- `{alias}` -> #{id}:{server_name}").unwrap(); writeln!(output, "- `{alias}` -> #{id}:{server_name}")
.expect("should be able to write to string buffer");
output output
}); });
@ -120,7 +122,7 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu
escape_html(id.as_ref()), escape_html(id.as_ref()),
server_name server_name
) )
.unwrap(); .expect("should be able to write to string buffer");
output output
}); });

View file

@ -1,4 +1,4 @@
use std::fmt::Write as _; use std::fmt::Write;
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId};
@ -48,7 +48,7 @@ pub(crate) async fn list(_body: Vec<&str>, page: Option<usize>) -> Result<RoomMe
members, members,
escape_html(name) escape_html(name)
) )
.unwrap(); .expect("should be able to write to string buffer");
output output
}) })
); );

View file

@ -1,4 +1,4 @@
use std::fmt::Write as _; use std::fmt::Write;
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId};
@ -65,7 +65,7 @@ pub(crate) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) ->
members, members,
escape_html(name.as_ref()) escape_html(name.as_ref())
) )
.unwrap(); .expect("should be able to write to string buffer");
output output
}) })
); );

View file

@ -122,7 +122,9 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
&local_user, &room_id &local_user, &room_id
); );
_ = leave_room(&local_user, &room_id, None).await; if let Err(e) = leave_room(&local_user, &room_id, None).await {
warn!(%e, "Failed to leave room");
}
} }
} else { } else {
for local_user in services() for local_user in services()
@ -329,7 +331,9 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
admins too)", admins too)",
&local_user, room_id &local_user, room_id
); );
_ = leave_room(&local_user, &room_id, None).await; if let Err(e) = leave_room(&local_user, &room_id, None).await {
warn!(%e, "Failed to leave room");
}
} }
} else { } else {
for local_user in services() for local_user in services()

View file

@ -65,7 +65,8 @@ pub(crate) async fn create(
.new_user_displayname_suffix .new_user_displayname_suffix
.is_empty() .is_empty()
{ {
_ = write!(displayname, " {}", services().globals.config.new_user_displayname_suffix); write!(displayname, " {}", services().globals.config.new_user_displayname_suffix)
.expect("should be able to write to string buffer");
} }
services() services()

View file

@ -1,4 +1,4 @@
use std::fmt::Write as _; use std::fmt::Write;
use register::RegistrationKind; use register::RegistrationKind;
use ruma::{ use ruma::{
@ -241,7 +241,8 @@ pub(crate) async fn register_route(body: Ruma<register::v3::Request>) -> Result<
// If `new_user_displayname_suffix` is set, registration will push whatever // If `new_user_displayname_suffix` is set, registration will push whatever
// content is set to the user's display name with a space before it // content is set to the user's display name with a space before it
if !services().globals.new_user_displayname_suffix().is_empty() { if !services().globals.new_user_displayname_suffix().is_empty() {
_ = write!(displayname, " {}", services().globals.config.new_user_displayname_suffix); write!(displayname, " {}", services().globals.config.new_user_displayname_suffix)
.expect("should be able to write to string buffer");
} }
services() services()

View file

@ -80,7 +80,9 @@ async fn banned_room_check(user_id: &UserId, room_id: Option<&RoomId>, server_na
// ignore errors // ignore errors
leave_all_rooms(user_id).await; leave_all_rooms(user_id).await;
_ = services().users.deactivate_account(user_id); if let Err(e) = services().users.deactivate_account(user_id) {
warn!(%e, "Failed to deactivate account");
}
} }
return Err(Error::BadRequest( return Err(Error::BadRequest(
@ -115,7 +117,9 @@ async fn banned_room_check(user_id: &UserId, room_id: Option<&RoomId>, server_na
// ignore errors // ignore errors
leave_all_rooms(user_id).await; leave_all_rooms(user_id).await;
_ = services().users.deactivate_account(user_id); if let Err(e) = services().users.deactivate_account(user_id) {
warn!(%e, "Failed to deactivate account");
}
} }
return Err(Error::BadRequest( return Err(Error::BadRequest(
@ -1548,8 +1552,12 @@ pub async fn leave_all_rooms(user_id: &UserId) {
}; };
// ignore errors // ignore errors
_ = services().rooms.state_cache.forget(&room_id, user_id); if let Err(e) = services().rooms.state_cache.forget(&room_id, user_id) {
_ = leave_room(user_id, &room_id, None).await; warn!(%e, "Failed to forget room");
}
if let Err(e) = leave_room(user_id, &room_id, None).await {
warn!(%e, "Failed to leave room");
}
} }
} }

View file

@ -12,6 +12,7 @@ use ruma::{
presence::PresenceState, presence::PresenceState,
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use tracing::warn;
use crate::{ use crate::{
service::{pdu::PduBuilder, user_is_local}, service::{pdu::PduBuilder, user_is_local},
@ -82,11 +83,14 @@ pub(crate) async fn set_displayname_route(
); );
let state_lock = mutex_state.lock().await; let state_lock = mutex_state.lock().await;
_ = services() if let Err(e) = services()
.rooms .rooms
.timeline .timeline
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
.await; .await
{
warn!(%e, "Failed to update/send new display name in room");
}
} }
if services().globals.allow_local_presence() { if services().globals.allow_local_presence() {
@ -224,11 +228,14 @@ pub(crate) async fn set_avatar_url_route(
); );
let state_lock = mutex_state.lock().await; let state_lock = mutex_state.lock().await;
_ = services() if let Err(e) = services()
.rooms .rooms
.timeline .timeline
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
.await; .await
{
warn!(%e, "Failed to set/update room with new avatar URL / pfp");
}
} }
if services().globals.allow_local_presence() { if services().globals.allow_local_presence() {

View file

@ -388,7 +388,7 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.") Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.")
})?; })?;
debug_warn!("initial state event: {event:?}"); debug_info!("Room creation initial state event: {event:?}");
// client/appservice workaround: if a user sends an initial_state event with a // client/appservice workaround: if a user sends an initial_state event with a
// state event in there with the content of literally `{}` (not null or empty // state event in there with the content of literally `{}` (not null or empty
@ -460,7 +460,9 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
// 8. Events implied by invite (and TODO: invite_3pid) // 8. Events implied by invite (and TODO: invite_3pid)
drop(state_lock); drop(state_lock);
for user_id in &body.invite { for user_id in &body.invite {
_ = invite_helper(sender_user, user_id, &room_id, None, body.is_direct).await; if let Err(e) = invite_helper(sender_user, user_id, &room_id, None, body.is_direct).await {
warn!(%e, "Failed to send invite");
}
} }
// Homeserver specific stuff // Homeserver specific stuff
@ -815,7 +817,7 @@ pub(crate) async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) ->
// Modify the power levels in the old room to prevent sending of events and // Modify the power levels in the old room to prevent sending of events and
// inviting new users // inviting new users
_ = services() services()
.rooms .rooms
.timeline .timeline
.build_and_append_pdu( .build_and_append_pdu(

View file

@ -866,7 +866,7 @@ impl fmt::Display for Config {
let mut msg: String = "Active config values:\n\n".to_owned(); let mut msg: String = "Active config values:\n\n".to_owned();
for line in lines.into_iter().enumerate() { for line in lines.into_iter().enumerate() {
let _ = writeln!(msg, "{}: {}", line.1 .0, line.1 .1); writeln!(msg, "{}: {}", line.1 .0, line.1 .1).expect("should be able to write to string buffer");
} }
write!(f, "{msg}") write!(f, "{msg}")

View file

@ -5,6 +5,7 @@ extern crate rust_rocksdb;
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::Write,
sync::{atomic::AtomicU32, Arc}, sync::{atomic::AtomicU32, Arc},
}; };
@ -99,6 +100,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
if !self.old_cfs.contains(&name.to_owned()) { if !self.old_cfs.contains(&name.to_owned()) {
// Create if it didn't exist // Create if it didn't exist
debug!("Creating new column family in database: {}", name); debug!("Creating new column family in database: {}", name);
_ = self.rocks.create_cf(name, &self.opts); _ = self.rocks.create_cf(name, &self.opts);
} }
@ -141,22 +143,19 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
fn memory_usage(&self) -> Result<String> { fn memory_usage(&self) -> Result<String> {
let mut res = String::new(); let mut res = String::new();
let stats = get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?; let stats = get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?;
_ = std::fmt::write( writeln!(
&mut res, res,
format_args!( "Memory buffers: {:.2} MiB\nPending write: {:.2} MiB\nTable readers: {:.2} MiB\nRow cache: {:.2} MiB",
"Memory buffers: {:.2} MiB\nPending write: {:.2} MiB\nTable readers: {:.2} MiB\nRow cache: {:.2} MiB\n", stats.mem_table_total as f64 / 1024.0 / 1024.0,
stats.mem_table_total as f64 / 1024.0 / 1024.0, stats.mem_table_unflushed as f64 / 1024.0 / 1024.0,
stats.mem_table_unflushed as f64 / 1024.0 / 1024.0, stats.mem_table_readers_total as f64 / 1024.0 / 1024.0,
stats.mem_table_readers_total as f64 / 1024.0 / 1024.0, self.row_cache.get_usage() as f64 / 1024.0 / 1024.0,
self.row_cache.get_usage() as f64 / 1024.0 / 1024.0, )
), .expect("should be able to write to string buffer");
);
for (name, cache) in &self.col_cache { for (name, cache) in &self.col_cache {
_ = std::fmt::write( writeln!(res, "{} cache: {:.2} MiB", name, cache.get_usage() as f64 / 1024.0 / 1024.0,)
&mut res, .expect("should be able to write to string buffer");
format_args!("{} cache: {:.2} MiB\n", name, cache.get_usage() as f64 / 1024.0 / 1024.0,),
);
} }
Ok(res) Ok(res)
@ -217,19 +216,17 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
let options = BackupEngineOptions::new(path.unwrap())?; let options = BackupEngineOptions::new(path.unwrap())?;
let engine = BackupEngine::open(&options, &self.env)?; let engine = BackupEngine::open(&options, &self.env)?;
for info in engine.get_backup_info() { for info in engine.get_backup_info() {
std::fmt::write( writeln!(
&mut res, res,
format_args!( "#{} {}: {} bytes, {} files",
"#{} {}: {} bytes, {} files\n", info.backup_id,
info.backup_id, DateTime::<Utc>::from_timestamp(info.timestamp, 0)
DateTime::<Utc>::from_timestamp(info.timestamp, 0) .unwrap_or_default()
.unwrap_or_default() .to_rfc2822(),
.to_rfc2822(), info.size,
info.size, info.num_files,
info.num_files,
),
) )
.unwrap(); .expect("should be able to write to string buffer");
} }
Ok(res) Ok(res)
@ -241,18 +238,12 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
Ok(files) => { Ok(files) => {
let mut res = String::new(); let mut res = String::new();
for file in files { for file in files {
let _ = std::fmt::write( writeln!(
&mut res, res,
format_args!( "<code>L{} {:<13} {:7}+ {:4}- {:9}</code> {}<br>",
"<code>L{} {:<13} {:7}+ {:4}- {:9}</code> {}<br>", file.level, file.name, file.num_entries, file.num_deletions, file.size, file.column_family_name,
file.level, )
file.name, .expect("should be able to writeln to string buffer");
file.num_entries,
file.num_deletions,
file.size,
file.column_family_name,
),
);
} }
Ok(res) Ok(res)
}, },

View file

@ -81,8 +81,7 @@ pub(crate) async fn start(server: Arc<Server>) -> Result<(), Error> {
services().start().await?; services().start().await?;
#[cfg(feature = "systemd")] #[cfg(feature = "systemd")]
#[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).expect("failed to notify systemd of ready state");
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]);
debug!("Started"); debug!("Started");
Ok(()) Ok(())
@ -115,8 +114,7 @@ pub(crate) async fn stop(_server: Arc<Server>) -> Result<(), Error> {
drop(s); drop(s);
#[cfg(feature = "systemd")] #[cfg(feature = "systemd")]
#[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]).expect("failed to notify systemd of stopping state");
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]);
info!("Shutdown complete."); info!("Shutdown complete.");
Ok(()) Ok(())

View file

@ -3,7 +3,7 @@ use std::time::Duration;
use ruma::events::room::message::RoomMessageEventContent; use ruma::events::room::message::RoomMessageEventContent;
use serde::Deserialize; use serde::Deserialize;
use tokio::{task::JoinHandle, time::interval}; use tokio::{task::JoinHandle, time::interval};
use tracing::{debug, error}; use tracing::{debug, error, warn};
use crate::{ use crate::{
conduit::{Error, Result}, conduit::{Error, Result},
@ -35,7 +35,9 @@ pub async fn start_check_for_updates_task() -> Result<JoinHandle<()>> {
}, },
} }
_ = try_handle_updates().await; if let Err(e) = try_handle_updates().await {
warn!(%e, "Failed to check for updates");
}
} }
})) }))
} }