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_field_names = { level = "allow", priority = 1 }
unnecessary_wraps = { level = "allow", priority = 1 }
unused_async = { level = "allow", priority = 1 }
###################
perf = { level = "warn", priority = -1 }

View File

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

View File

@@ -10,7 +10,7 @@ use tuwunel_service::Services;
use crate::Ruma;
pub(super) async fn handle_login(
pub(super) fn handle_login(
services: &Services,
body: &Ruma<Request>,
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::Jwt(info) => jwt::handle_login(&services, &body, info).await?,
| LoginInfo::ApplicationService(info) =>
appservice::handle_login(&services, &body, info).await?,
appservice::handle_login(&services, &body, info)?,
| _ => {
return Err!(Request(Unknown(debug_warn!(
?body.login_info,

View File

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

View File

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

View File

@@ -10,11 +10,12 @@ use crate::{
};
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 = "<'_>")]
#[allow(clippy::unused_async)]
};
item.attrs.push(attr);
item.attrs.extend(attr);
Ok(item.into_token_stream().into())
}

View File

@@ -4,7 +4,6 @@ use std::{
};
use axum_server::Handle as ServerHandle;
use futures::FutureExt;
use tokio::{
sync::broadcast::{self, Sender},
task::JoinHandle,
@@ -106,14 +105,11 @@ pub(crate) async fn stop(services: Arc<Services>) -> Result {
#[tracing::instrument(skip_all)]
async fn signal(server: Arc<Server>, tx: Sender<()>, handle: axum_server::Handle) {
server
.clone()
.until_shutdown()
.then(move |()| handle_shutdown(server, tx, handle))
.await;
server.until_shutdown().await;
handle_shutdown(&server, &tx, &handle);
}
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(()) {
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() {
self.interrupt();
} else if sig == "SIGINT" {
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");
if worker_join.is_none() {
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.
#[implement(super::Service)]
#[allow(clippy::unused_async)]
pub(super) async fn console_auto_start(&self) {
#[cfg(feature = "console")]
if self
@@ -16,12 +17,13 @@ pub(super) async fn console_auto_start(&self) {
{
// Allow more of the startup sequence to execute before spawning
tokio::task::yield_now().await;
self.console.start().await;
self.console.start();
}
}
/// Shutdown the console when the admin worker terminates.
#[implement(super::Service)]
#[allow(clippy::unused_async)]
pub(super) async fn console_auto_stop(&self) {
#[cfg(feature = "console")]
self.console.close().await;

View File

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

View File

@@ -106,7 +106,7 @@ impl Service {
#[must_use]
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();
if let Some(file) = &self
.server

View File

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

View File

@@ -49,13 +49,13 @@ pub struct UrlPreviewData {
}
#[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
self.db.remove_url_preview(url)
}
#[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()
.duration_since(SystemTime::UNIX_EPOCH)
.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"))),
};
self.set_url_preview(url.as_str(), &data).await?;
self.set_url_preview(url.as_str(), &data)?;
Ok(data)
}
@@ -165,6 +165,7 @@ pub async fn download_image(&self, url: &str) -> Result<UrlPreviewData> {
#[cfg(not(feature = "url_preview"))]
#[implement(Service)]
#[allow(clippy::unused_async)]
pub async fn download_image(&self, _url: &str) -> Result<UrlPreviewData> {
Err!(FeatureDisabled("url_preview"))
}
@@ -214,6 +215,7 @@ async fn download_html(&self, url: &str) -> Result<UrlPreviewData> {
#[cfg(not(feature = "url_preview"))]
#[implement(Service)]
#[allow(clippy::unused_async)]
async fn download_html(&self, _url: &str) -> Result<UrlPreviewData> {
Err!(FeatureDisabled("url_preview"))
}

View File

@@ -198,7 +198,7 @@ async fn hooked_resolve(
name: Name,
) -> Result<Addrs, Box<dyn std::error::Error + Send + Sync>> {
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() =>
resolve_to_reqwest(
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
.ips
.into_iter()

View File

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

View File

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

View File

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

View File

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

View File

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