Skip to content

Commit

Permalink
clippy: disallow useless asyncs (#3513)
Browse files Browse the repository at this point in the history
Using async when not required will increase compile times, and propagate async-ness to the callers, transitively.

See also the [lint description](https://rust-lang.github.io/rust-clippy/master/#/unused_async).

Since we only had a few false positives, I've enabled it by default.
  • Loading branch information
bnjbvr authored Jun 5, 2024
1 parent 23cc1e3 commit 5093af8
Show file tree
Hide file tree
Showing 37 changed files with 156 additions and 175 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rustflags = [
"-Wclippy::nonstandard_macro_braces",
"-Wclippy::str_to_string",
"-Wclippy::todo",
"-Wclippy::unused_async",
]

[target.'cfg(target_arch = "wasm32")']
Expand Down
12 changes: 3 additions & 9 deletions bindings/matrix-sdk-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,7 @@ impl OlmMachine {
let methods = methods.into_iter().map(VerificationMethod::from).collect();

Ok(if let Some(identity) = identity.and_then(|i| i.other()) {
let content =
self.runtime.block_on(identity.verification_request_content(Some(methods)));
let content = identity.verification_request_content(Some(methods));
Some(serde_json::to_string(&content)?)
} else {
None
Expand Down Expand Up @@ -1202,11 +1201,7 @@ impl OlmMachine {
let methods = methods.into_iter().map(VerificationMethod::from).collect();

Ok(if let Some(identity) = identity.and_then(|i| i.other()) {
let request = self.runtime.block_on(identity.request_verification(
&room_id,
&event_id,
Some(methods),
));
let request = identity.request_verification(&room_id, &event_id, Some(methods));

Some(
VerificationRequest { inner: request, runtime: self.runtime.handle().to_owned() }
Expand Down Expand Up @@ -1243,8 +1238,7 @@ impl OlmMachine {
if let Some(device) =
self.runtime.block_on(self.inner.get_device(&user_id, device_id, None))?
{
let (verification, request) =
self.runtime.block_on(device.request_verification_with_methods(methods));
let (verification, request) = device.request_verification_with_methods(methods);

Some(RequestVerificationResult {
verification: VerificationRequest {
Expand Down
8 changes: 4 additions & 4 deletions bindings/matrix-sdk-ffi/src/authentication_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl AuthenticationService {

let oidc_metadata: VerifiedClientMetadata = configuration.try_into()?;

if self.load_client_registration(oidc, issuer.clone(), oidc_metadata.clone()).await {
if self.load_client_registration(oidc, issuer.clone(), oidc_metadata.clone()) {
tracing::info!("OIDC configuration loaded from disk.");
return Ok(());
}
Expand All @@ -472,14 +472,14 @@ impl AuthenticationService {
oidc.restore_registered_client(issuer, oidc_metadata, credentials);

tracing::info!("Persisting OIDC registration data.");
self.store_client_registration(oidc).await?;
self.store_client_registration(oidc)?;

Ok(())
}

/// Stores the current OIDC dynamic client registration so it can be re-used
/// if we ever log in via the same issuer again.
async fn store_client_registration(&self, oidc: &Oidc) -> Result<(), AuthenticationError> {
fn store_client_registration(&self, oidc: &Oidc) -> Result<(), AuthenticationError> {
let issuer = Url::parse(oidc.issuer().ok_or(AuthenticationError::OidcNotSupported)?)
.map_err(|_| AuthenticationError::OidcError {
message: String::from("Failed to parse issuer URL."),
Expand Down Expand Up @@ -508,7 +508,7 @@ impl AuthenticationService {

/// Attempts to load an existing OIDC dynamic client registration for the
/// currently configured issuer.
async fn load_client_registration(
fn load_client_registration(
&self,
oidc: &Oidc,
issuer: String,
Expand Down
14 changes: 6 additions & 8 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ impl Client {
let session_delegate = session_delegate.clone();
Box::new(move |client| {
let session_delegate = session_delegate.clone();
Box::pin(
async move { Ok(Self::save_session(session_delegate, client).await?) },
)
Ok(Self::save_session(session_delegate, client)?)
})
},
)?;
Expand Down Expand Up @@ -415,8 +413,8 @@ impl Client {
})
}

pub async fn session(&self) -> Result<Session, ClientError> {
Self::session_inner((*self.inner).clone()).await
pub fn session(&self) -> Result<Session, ClientError> {
Self::session_inner((*self.inner).clone())
}

pub async fn account_url(
Expand Down Expand Up @@ -968,7 +966,7 @@ impl Client {
}
}

async fn session_inner(client: matrix_sdk::Client) -> Result<Session, ClientError> {
fn session_inner(client: matrix_sdk::Client) -> Result<Session, ClientError> {
let auth_api = client.auth_api().context("Missing authentication API")?;

let homeserver_url = client.homeserver().into();
Expand All @@ -977,11 +975,11 @@ impl Client {
Session::new(auth_api, homeserver_url, sliding_sync_proxy)
}

async fn save_session(
fn save_session(
session_delegate: Arc<dyn ClientSessionDelegate>,
client: matrix_sdk::Client,
) -> anyhow::Result<()> {
let session = Self::session_inner(client).await?;
let session = Self::session_inner(client)?;
session_delegate.save_session_in_keychain(session);
Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ impl RoomListItem {
Ok(RoomInfo::new(self.inner.inner_room(), latest_event).await?)
}

/// Building a `Room`. If its internal timeline hasn't been initialized
/// it'll fail.
async fn full_room(&self) -> Result<Arc<Room>, RoomListError> {
/// Build a full `Room` FFI object, filling its associated timeline.
///
/// If its internal timeline hasn't been initialized, it'll fail.
fn full_room(&self) -> Result<Arc<Room>, RoomListError> {
if let Some(timeline) = self.inner.timeline() {
Ok(Arc::new(Room::with_timeline(
self.inner.inner_room().clone(),
Expand Down
3 changes: 1 addition & 2 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ impl BaseClient {
room_info,
changes,
)
.await;
} else {
push_context = self.get_push_room_context(room, room_info, changes).await?;
}
Expand Down Expand Up @@ -1409,7 +1408,7 @@ impl BaseClient {
/// Update the push context for the given room.
///
/// Updates the context data from `changes` or `room_info`.
pub async fn update_push_room_context(
pub fn update_push_room_context(
&self,
push_rules: &mut PushConditionRoomCtx,
user_id: &UserId,
Expand Down
Loading

0 comments on commit 5093af8

Please sign in to comment.