Enable unused_async clippy lint

This commit is contained in:
dasha_uwu
2026-01-10 09:08:48 +05:00
committed by Jason Volk
parent fd519ff7f1
commit d095a4fd3b
20 changed files with 60 additions and 64 deletions

View File

@@ -929,7 +929,6 @@ single_match_else = { level = "allow", priority = 1 }
struct_excessive_bools = { level = "allow", priority = 1 } struct_excessive_bools = { level = "allow", priority = 1 }
struct_field_names = { level = "allow", priority = 1 } struct_field_names = { level = "allow", priority = 1 }
unnecessary_wraps = { level = "allow", priority = 1 } unnecessary_wraps = { level = "allow", priority = 1 }
unused_async = { level = "allow", priority = 1 }
################### ###################
perf = { level = "warn", priority = -1 } perf = { level = "warn", priority = -1 }

View File

@@ -266,7 +266,6 @@ pub(crate) async fn register_route(
let skip_auth = if !services let skip_auth = if !services
.globals .globals
.get_registration_tokens() .get_registration_tokens()
.await
.is_empty() .is_empty()
&& !is_guest && !is_guest
{ {
@@ -425,7 +424,7 @@ pub(crate) async fn check_registration_token_validity(
State(services): State<crate::State>, State(services): State<crate::State>,
body: Ruma<check_registration_token_validity::v1::Request>, body: Ruma<check_registration_token_validity::v1::Request>,
) -> Result<check_registration_token_validity::v1::Response> { ) -> Result<check_registration_token_validity::v1::Response> {
let tokens = services.globals.get_registration_tokens().await; let tokens = services.globals.get_registration_tokens();
if tokens.is_empty() { if tokens.is_empty() {
return Err!(Request(Forbidden("Server does not allow token registration"))); return Err!(Request(Forbidden("Server does not allow token registration")));

View File

@@ -10,7 +10,7 @@ use tuwunel_service::Services;
use crate::Ruma; use crate::Ruma;
pub(super) async fn handle_login( pub(super) fn handle_login(
services: &Services, services: &Services,
body: &Ruma<Request>, body: &Ruma<Request>,
info: &ApplicationService, info: &ApplicationService,

View File

@@ -115,7 +115,7 @@ pub(crate) async fn login_route(
| LoginInfo::Token(info) => token::handle_login(&services, &body, info).await?, | LoginInfo::Token(info) => token::handle_login(&services, &body, info).await?,
| LoginInfo::Jwt(info) => jwt::handle_login(&services, &body, info).await?, | LoginInfo::Jwt(info) => jwt::handle_login(&services, &body, info).await?,
| LoginInfo::ApplicationService(info) => | LoginInfo::ApplicationService(info) =>
appservice::handle_login(&services, &body, info).await?, appservice::handle_login(&services, &body, info)?,
| _ => { | _ => {
return Err!(Request(Unknown(debug_warn!( return Err!(Request(Unknown(debug_warn!(
?body.login_info, ?body.login_info,

View File

@@ -1,7 +1,6 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use axum::extract::State; use axum::extract::State;
use futures::StreamExt;
use ruma::{ use ruma::{
api::{ api::{
client::{error::ErrorKind, to_device::send_event_to_device}, client::{error::ErrorKind, to_device::send_event_to_device},
@@ -9,7 +8,7 @@ use ruma::{
}, },
to_device::DeviceIdOrAllDevices, to_device::DeviceIdOrAllDevices,
}; };
use tuwunel_core::{Error, Result}; use tuwunel_core::{Error, Result, utils::ReadyExt};
use tuwunel_service::sending::EduBuf; use tuwunel_service::sending::EduBuf;
use crate::Ruma; use crate::Ruma;
@@ -69,31 +68,27 @@ pub(crate) async fn send_event_to_device_route(
match target_device_id_maybe { match target_device_id_maybe {
| DeviceIdOrAllDevices::DeviceId(target_device_id) => { | DeviceIdOrAllDevices::DeviceId(target_device_id) => {
services services.users.add_to_device_event(
.users sender_user,
.add_to_device_event( target_user_id,
sender_user, target_device_id,
target_user_id, event_type,
target_device_id, &event,
event_type, );
event,
)
.await;
}, },
| DeviceIdOrAllDevices::AllDevices => { | DeviceIdOrAllDevices::AllDevices => {
let (event_type, event) = (&event_type, &event);
services services
.users .users
.all_device_ids(target_user_id) .all_device_ids(target_user_id)
.for_each(|target_device_id| { .ready_for_each(|target_device_id| {
services.users.add_to_device_event( services.users.add_to_device_event(
sender_user, sender_user,
target_user_id, target_user_id,
target_device_id, target_device_id,
event_type, event_type,
event.clone(), &event,
) );
}) })
.await; .await;
}, },

View File

@@ -538,24 +538,27 @@ async fn handle_edu_direct_to_device_event(
) { ) {
match target_device_id_maybe { match target_device_id_maybe {
| DeviceIdOrAllDevices::DeviceId(ref target_device_id) => { | DeviceIdOrAllDevices::DeviceId(ref target_device_id) => {
services services.users.add_to_device_event(
.users sender,
.add_to_device_event(sender, target_user_id, target_device_id, ev_type, event) target_user_id,
.await; target_device_id,
ev_type,
&event,
);
}, },
| DeviceIdOrAllDevices::AllDevices => { | DeviceIdOrAllDevices::AllDevices => {
services services
.users .users
.all_device_ids(target_user_id) .all_device_ids(target_user_id)
.for_each(|target_device_id| { .ready_for_each(|target_device_id| {
services.users.add_to_device_event( services.users.add_to_device_event(
sender, sender,
target_user_id, target_user_id,
target_device_id, target_device_id,
ev_type, ev_type,
event.clone(), &event,
) );
}) })
.await; .await;
}, },

View File

@@ -10,11 +10,12 @@ use crate::{
}; };
pub(super) fn command(mut item: ItemFn, _args: &[Meta]) -> Result<TokenStream> { pub(super) fn command(mut item: ItemFn, _args: &[Meta]) -> Result<TokenStream> {
let attr: Attribute = parse_quote! { let attr: Vec<Attribute> = parse_quote! {
#[tuwunel_macros::implement(crate::Context, params = "<'_>")] #[tuwunel_macros::implement(crate::Context, params = "<'_>")]
#[allow(clippy::unused_async)]
}; };
item.attrs.push(attr); item.attrs.extend(attr);
Ok(item.into_token_stream().into()) Ok(item.into_token_stream().into())
} }

View File

@@ -4,7 +4,6 @@ use std::{
}; };
use axum_server::Handle as ServerHandle; use axum_server::Handle as ServerHandle;
use futures::FutureExt;
use tokio::{ use tokio::{
sync::broadcast::{self, Sender}, sync::broadcast::{self, Sender},
task::JoinHandle, task::JoinHandle,
@@ -106,14 +105,11 @@ pub(crate) async fn stop(services: Arc<Services>) -> Result {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn signal(server: Arc<Server>, tx: Sender<()>, handle: axum_server::Handle) { async fn signal(server: Arc<Server>, tx: Sender<()>, handle: axum_server::Handle) {
server server.until_shutdown().await;
.clone() handle_shutdown(&server, &tx, &handle);
.until_shutdown()
.then(move |()| handle_shutdown(server, tx, handle))
.await;
} }
async fn handle_shutdown(server: Arc<Server>, tx: Sender<()>, handle: axum_server::Handle) { fn handle_shutdown(server: &Arc<Server>, tx: &Sender<()>, handle: &axum_server::Handle) {
if let Err(e) = tx.send(()) { if let Err(e) = tx.send(()) {
error!("failed sending shutdown transaction to channel: {e}"); error!("failed sending shutdown transaction to channel: {e}");
} }

View File

@@ -38,16 +38,16 @@ impl Console {
}) })
} }
pub(super) async fn handle_signal(self: &Arc<Self>, sig: &'static str) { pub(super) fn handle_signal(self: &Arc<Self>, sig: &'static str) {
if !self.server.running() { if !self.server.running() {
self.interrupt(); self.interrupt();
} else if sig == "SIGINT" { } else if sig == "SIGINT" {
self.interrupt_command(); self.interrupt_command();
self.start().await; self.start();
} }
} }
pub async fn start(self: &Arc<Self>) { pub fn start(self: &Arc<Self>) {
let mut worker_join = self.worker_join.lock().expect("locked"); let mut worker_join = self.worker_join.lock().expect("locked");
if worker_join.is_none() { if worker_join.is_none() {
let self_ = Arc::clone(self); let self_ = Arc::clone(self);

View File

@@ -6,6 +6,7 @@ pub(super) const SIGNAL: &str = "SIGUSR2";
/// Possibly spawn the terminal console at startup if configured. /// Possibly spawn the terminal console at startup if configured.
#[implement(super::Service)] #[implement(super::Service)]
#[allow(clippy::unused_async)]
pub(super) async fn console_auto_start(&self) { pub(super) async fn console_auto_start(&self) {
#[cfg(feature = "console")] #[cfg(feature = "console")]
if self if self
@@ -16,12 +17,13 @@ pub(super) async fn console_auto_start(&self) {
{ {
// Allow more of the startup sequence to execute before spawning // Allow more of the startup sequence to execute before spawning
tokio::task::yield_now().await; tokio::task::yield_now().await;
self.console.start().await; self.console.start();
} }
} }
/// Shutdown the console when the admin worker terminates. /// Shutdown the console when the admin worker terminates.
#[implement(super::Service)] #[implement(super::Service)]
#[allow(clippy::unused_async)]
pub(super) async fn console_auto_stop(&self) { pub(super) async fn console_auto_stop(&self) {
#[cfg(feature = "console")] #[cfg(feature = "console")]
self.console.close().await; self.console.close().await;

View File

@@ -194,7 +194,7 @@ impl Service {
} }
#[cfg(feature = "console")] #[cfg(feature = "console")]
self.console.handle_signal(sig).await; self.console.handle_signal(sig);
} }
async fn handle_command(&self, command: CommandInput) { async fn handle_command(&self, command: CommandInput) {

View File

@@ -106,7 +106,7 @@ impl Service {
#[must_use] #[must_use]
pub fn is_read_only(&self) -> bool { self.db.db.is_read_only() } pub fn is_read_only(&self) -> bool { self.db.db.is_read_only() }
pub async fn get_registration_tokens(&self) -> HashSet<String> { pub fn get_registration_tokens(&self) -> HashSet<String> {
let mut tokens = HashSet::new(); let mut tokens = HashSet::new();
if let Some(file) = &self if let Some(file) = &self
.server .server

View File

@@ -57,7 +57,7 @@ impl Manager {
debug!("Starting service workers..."); debug!("Starting service workers...");
for service in self.services.services() { for service in self.services.services() {
self.start_worker(&mut workers, &service).await?; self.start_worker(&mut workers, &service)?;
} }
Ok(()) Ok(())
@@ -78,7 +78,7 @@ impl Manager {
tokio::select! { tokio::select! {
result = workers.join_next() => match result { result = workers.join_next() => match result {
Some(Ok(result)) => self.handle_result(&mut workers, result).await?, Some(Ok(result)) => self.handle_result(&mut workers, result).await?,
Some(Err(error)) => self.handle_abort(&mut workers, Error::from(error)).await?, Some(Err(error)) => self.handle_abort(&mut workers, &Error::from(error))?,
None => break, None => break,
} }
} }
@@ -88,7 +88,8 @@ impl Manager {
Ok(()) Ok(())
} }
async fn handle_abort(&self, _workers: &mut WorkersLocked<'_>, error: Error) -> Result { #[allow(clippy::unused_self)]
fn handle_abort(&self, _workers: &mut WorkersLocked<'_>, error: &Error) -> Result {
// not supported until service can be associated with abort // not supported until service can be associated with abort
unimplemented!("unexpected worker task abort {error:?}"); unimplemented!("unexpected worker task abort {error:?}");
} }
@@ -100,12 +101,13 @@ impl Manager {
) -> Result { ) -> Result {
let (service, result) = result; let (service, result) = result;
match result { match result {
| Ok(()) => self.handle_finished(workers, &service).await, | Ok(()) => self.handle_finished(workers, &service),
| Err(error) => self.handle_error(workers, &service, error).await, | Err(error) => self.handle_error(workers, &service, error).await,
} }
} }
async fn handle_finished( #[allow(clippy::unused_self)]
fn handle_finished(
&self, &self,
_workers: &mut WorkersLocked<'_>, _workers: &mut WorkersLocked<'_>,
service: &Arc<dyn Service>, service: &Arc<dyn Service>,
@@ -136,11 +138,11 @@ impl Manager {
warn!("service {name:?} worker restarting after {} delay", time::pretty(delay)); warn!("service {name:?} worker restarting after {} delay", time::pretty(delay));
sleep(delay).await; sleep(delay).await;
self.start_worker(workers, service).await self.start_worker(workers, service)
} }
/// Start the worker in a task for the service. /// Start the worker in a task for the service.
async fn start_worker( fn start_worker(
&self, &self,
workers: &mut WorkersLocked<'_>, workers: &mut WorkersLocked<'_>,
service: &Arc<dyn Service>, service: &Arc<dyn Service>,

View File

@@ -49,13 +49,13 @@ pub struct UrlPreviewData {
} }
#[implement(Service)] #[implement(Service)]
pub async fn remove_url_preview(&self, url: &str) -> Result { pub fn remove_url_preview(&self, url: &str) -> Result {
// TODO: also remove the downloaded image // TODO: also remove the downloaded image
self.db.remove_url_preview(url) self.db.remove_url_preview(url)
} }
#[implement(Service)] #[implement(Service)]
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result { pub fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result {
let now = SystemTime::now() let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH) .duration_since(SystemTime::UNIX_EPOCH)
.expect("valid system time"); .expect("valid system time");
@@ -117,7 +117,7 @@ async fn request_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
| _ => return Err!(Request(Unknown("Unsupported Content-Type"))), | _ => return Err!(Request(Unknown("Unsupported Content-Type"))),
}; };
self.set_url_preview(url.as_str(), &data).await?; self.set_url_preview(url.as_str(), &data)?;
Ok(data) Ok(data)
} }
@@ -165,6 +165,7 @@ pub async fn download_image(&self, url: &str) -> Result<UrlPreviewData> {
#[cfg(not(feature = "url_preview"))] #[cfg(not(feature = "url_preview"))]
#[implement(Service)] #[implement(Service)]
#[allow(clippy::unused_async)]
pub async fn download_image(&self, _url: &str) -> Result<UrlPreviewData> { pub async fn download_image(&self, _url: &str) -> Result<UrlPreviewData> {
Err!(FeatureDisabled("url_preview")) Err!(FeatureDisabled("url_preview"))
} }
@@ -214,6 +215,7 @@ async fn download_html(&self, url: &str) -> Result<UrlPreviewData> {
#[cfg(not(feature = "url_preview"))] #[cfg(not(feature = "url_preview"))]
#[implement(Service)] #[implement(Service)]
#[allow(clippy::unused_async)]
async fn download_html(&self, _url: &str) -> Result<UrlPreviewData> { async fn download_html(&self, _url: &str) -> Result<UrlPreviewData> {
Err!(FeatureDisabled("url_preview")) Err!(FeatureDisabled("url_preview"))
} }

View File

@@ -198,7 +198,7 @@ async fn hooked_resolve(
name: Name, name: Name,
) -> Result<Addrs, Box<dyn std::error::Error + Send + Sync>> { ) -> Result<Addrs, Box<dyn std::error::Error + Send + Sync>> {
match cache.get_override(name.as_str()).await { match cache.get_override(name.as_str()).await {
| Ok(cached) if cached.valid() => cached_to_reqwest(cached).await, | Ok(cached) if cached.valid() => cached_to_reqwest(cached),
| Ok(CachedOverride { overriding, .. }) if overriding.is_some() => | Ok(CachedOverride { overriding, .. }) if overriding.is_some() =>
resolve_to_reqwest( resolve_to_reqwest(
server, server,
@@ -241,7 +241,7 @@ async fn resolve_to_reqwest(
} }
} }
async fn cached_to_reqwest(cached: CachedOverride) -> ResolvingResult { fn cached_to_reqwest(cached: CachedOverride) -> ResolvingResult {
let addrs = cached let addrs = cached
.ips .ips
.into_iter() .into_iter()

View File

@@ -172,7 +172,6 @@ impl Service {
self.services self.services
.state .state
.delete_room_shortstatehash(room_id, &state_lock) .delete_room_shortstatehash(room_id, &state_lock)
.await
.log_err() .log_err()
.ok(); .ok();

View File

@@ -526,7 +526,7 @@ pub async fn get_shortstatehash(&self, shorteventid: ShortEventId) -> Result<Sho
} }
#[implement(Service)] #[implement(Service)]
pub(super) async fn delete_room_shortstatehash( pub(super) fn delete_room_shortstatehash(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
_mutex_lock: &Guard<OwnedRoomId, ()>, _mutex_lock: &Guard<OwnedRoomId, ()>,

View File

@@ -149,11 +149,7 @@ pub async fn try_auth(
uiaainfo.completed.push(AuthType::Password); uiaainfo.completed.push(AuthType::Password);
}, },
| AuthData::RegistrationToken(t) => { | AuthData::RegistrationToken(t) => {
let tokens = self let tokens = self.services.globals.get_registration_tokens();
.services
.globals
.get_registration_tokens()
.await;
if tokens.contains(t.token.trim()) { if tokens.contains(t.token.trim()) {
uiaainfo uiaainfo
.completed .completed

View File

@@ -300,13 +300,13 @@ pub fn generate_refresh_token() -> String {
} }
#[implement(super::Service)] #[implement(super::Service)]
pub async fn add_to_device_event( pub fn add_to_device_event(
&self, &self,
sender: &UserId, sender: &UserId,
target_user_id: &UserId, target_user_id: &UserId,
target_device_id: &DeviceId, target_device_id: &DeviceId,
event_type: &str, event_type: &str,
content: serde_json::Value, content: &serde_json::Value,
) { ) {
let count = self.services.globals.next_count(); let count = self.services.globals.next_count();

View File

@@ -381,11 +381,13 @@ impl Service {
} }
#[cfg(not(feature = "ldap"))] #[cfg(not(feature = "ldap"))]
#[allow(clippy::unused_async)]
pub async fn search_ldap(&self, _user_id: &UserId) -> Result<Vec<(String, bool)>> { pub async fn search_ldap(&self, _user_id: &UserId) -> Result<Vec<(String, bool)>> {
Err!(FeatureDisabled("ldap")) Err!(FeatureDisabled("ldap"))
} }
#[cfg(not(feature = "ldap"))] #[cfg(not(feature = "ldap"))]
#[allow(clippy::unused_async)]
pub async fn auth_ldap(&self, _user_dn: &str, _password: &str) -> Result { pub async fn auth_ldap(&self, _user_dn: &str, _password: &str) -> Result {
Err!(FeatureDisabled("ldap")) Err!(FeatureDisabled("ldap"))
} }