From 12cd1effdc1021f8bd55e61cd80b702fca1514bf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 1 Apr 2026 21:03:24 +0200 Subject: [PATCH] refactor(ffi): Fix new clippy lints --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 23 +++++++------- bindings/matrix-sdk-ffi-macros/src/lib.rs | 16 +++++----- bindings/matrix-sdk-ffi/src/client.rs | 28 ++++++++--------- bindings/matrix-sdk-ffi/src/client_builder.rs | 11 ++++--- bindings/matrix-sdk-ffi/src/error.rs | 29 +++++++++--------- bindings/matrix-sdk-ffi/src/platform/mod.rs | 8 ++--- .../src/platform/rolling_writer.rs | 27 ++++++++--------- bindings/matrix-sdk-ffi/src/room/mod.rs | 11 ++++--- .../src/session_verification.rs | 30 ++++++++----------- bindings/matrix-sdk-ffi/src/utd.rs | 8 ++--- 10 files changed, 89 insertions(+), 102 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index fc0e0c266..468ac4cc3 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -913,22 +913,19 @@ impl OlmMachine { &decryption_settings, ))?; - if handle_verification_events { - if let Ok(AnyTimelineEvent::MessageLike(e)) = decrypted.event.deserialize() { - match &e { - AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original( - original_event, - )) => { - if let MessageType::VerificationRequest(_) = &original_event.content.msgtype - { - self.runtime.block_on(self.inner.receive_verification_event(&e))?; - } - } - _ if e.event_type().to_string().starts_with("m.key.verification") => { + if handle_verification_events + && let Ok(AnyTimelineEvent::MessageLike(e)) = decrypted.event.deserialize() + { + match &e { + AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(original_event)) => { + if let MessageType::VerificationRequest(_) = &original_event.content.msgtype { self.runtime.block_on(self.inner.receive_verification_event(&e))?; } - _ => (), } + _ if e.event_type().to_string().starts_with("m.key.verification") => { + self.runtime.block_on(self.inner.receive_verification_event(&e))?; + } + _ => (), } } diff --git a/bindings/matrix-sdk-ffi-macros/src/lib.rs b/bindings/matrix-sdk-ffi-macros/src/lib.rs index 371a51049..69e1e6e53 100644 --- a/bindings/matrix-sdk-ffi-macros/src/lib.rs +++ b/bindings/matrix-sdk-ffi-macros/src/lib.rs @@ -27,18 +27,18 @@ pub fn export(attr: TokenStream, item: TokenStream) -> TokenStream { } } else if let Item::Impl(blk) = &item { for item in &blk.items { - if let ImplItem::Fn(fun) = item { - if fun.sig.asyncness.is_some() { - return true; - } + if let ImplItem::Fn(fun) = item + && fun.sig.asyncness.is_some() + { + return true; } } } else if let Item::Trait(blk) = &item { for item in &blk.items { - if let TraitItem::Fn(fun) = item { - if fun.sig.asyncness.is_some() { - return true; - } + if let TraitItem::Fn(fun) = item + && fun.sig.asyncness.is_some() + { + return true; } } } diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 05488ec47..dbe837e92 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -367,12 +367,12 @@ impl Client { let controller = session_verification_controller.clone(); sdk_client.add_event_handler(move |event: OriginalSyncRoomMessageEvent| async move { - if let MessageType::VerificationRequest(_) = &event.content.msgtype { - if let Some(session_verification_controller) = &*controller.clone().read().await { - session_verification_controller - .process_incoming_verification_request(&event.sender, event.event_id) - .await; - } + if let MessageType::VerificationRequest(_) = &event.content.msgtype + && let Some(session_verification_controller) = &*controller.clone().read().await + { + session_verification_controller + .process_incoming_verification_request(&event.sender, event.event_id) + .await; } }); @@ -2132,10 +2132,10 @@ impl Client { let room_id = RoomId::parse(room_id)?; // Emit the initial event, if present - if let Some(room) = self.inner.get_room(&room_id) { - if let Ok(room_info) = RoomInfo::new(&room).await { - listener.call(room_info); - } + if let Some(room) = self.inner.get_room(&room_id) + && let Ok(room_info) = RoomInfo::new(&room).await + { + listener.call(room_info); } Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn({ @@ -2147,10 +2147,10 @@ impl Client { continue; } - if let Some(room) = client.get_room(&room_id) { - if let Ok(room_info) = RoomInfo::new(&room).await { - listener.call(room_info); - } + if let Some(room) = client.get_room(&room_id) + && let Ok(room_info) = RoomInfo::new(&room).await + { + listener.call(room_info); } } } diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index b16a56c3a..857683a69 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -490,12 +490,11 @@ impl ClientBuilder { updated_config = updated_config.timeout(Duration::from_millis(timeout)); } updated_config = updated_config.read_timeout(DEFAULT_READ_TIMEOUT); - if let Some(max_concurrent_requests) = config.max_concurrent_requests { - if max_concurrent_requests > 0 { - updated_config = updated_config.max_concurrent_requests(NonZeroUsize::new( - max_concurrent_requests as usize, - )); - } + if let Some(max_concurrent_requests) = config.max_concurrent_requests + && max_concurrent_requests > 0 + { + updated_config = updated_config + .max_concurrent_requests(NonZeroUsize::new(max_concurrent_requests as usize)); } if let Some(max_retry_time) = config.max_retry_time { updated_config = diff --git a/bindings/matrix-sdk-ffi/src/error.rs b/bindings/matrix-sdk-ffi/src/error.rs index 6370f6c6f..a9159a001 100644 --- a/bindings/matrix-sdk-ffi/src/error.rs +++ b/bindings/matrix-sdk-ffi/src/error.rs @@ -77,22 +77,21 @@ impl From for ClientError { fn from(e: matrix_sdk::Error) -> Self { match e { matrix_sdk::Error::Http(http_error) => { - if let Some(api_error) = http_error.as_client_api_error() { - if let ErrorBody::Standard(StandardErrorBody { kind, message, .. }) = + if let Some(api_error) = http_error.as_client_api_error() + && let ErrorBody::Standard(StandardErrorBody { kind, message, .. }) = &api_error.body - { - let code = kind.errcode().to_string(); - let Ok(kind) = kind.to_owned().try_into() else { - // We couldn't parse the API error, so we return a generic one instead - return (*http_error).into(); - }; - return Self::MatrixApi { - kind, - code, - msg: message.to_owned(), - details: Some(format!("{api_error:?}")), - }; - } + { + let code = kind.errcode().to_string(); + let Ok(kind) = kind.to_owned().try_into() else { + // We couldn't parse the API error, so we return a generic one instead + return (*http_error).into(); + }; + return Self::MatrixApi { + kind, + code, + msg: message.to_owned(), + details: Some(format!("{api_error:?}")), + }; } (*http_error).into() } diff --git a/bindings/matrix-sdk-ffi/src/platform/mod.rs b/bindings/matrix-sdk-ffi/src/platform/mod.rs index 69b423512..d0c886c18 100644 --- a/bindings/matrix-sdk-ffi/src/platform/mod.rs +++ b/bindings/matrix-sdk-ffi/src/platform/mod.rs @@ -149,10 +149,10 @@ where write!(writer, "{}", span.name())?; - if let Some(fields) = &span.extensions().get::>() { - if !fields.is_empty() { - write!(writer, "{{{fields}}}")?; - } + if let Some(fields) = &span.extensions().get::>() + && !fields.is_empty() + { + write!(writer, "{{{fields}}}")?; } } } diff --git a/bindings/matrix-sdk-ffi/src/platform/rolling_writer.rs b/bindings/matrix-sdk-ffi/src/platform/rolling_writer.rs index 9a22b1f7b..277cf494e 100644 --- a/bindings/matrix-sdk-ffi/src/platform/rolling_writer.rs +++ b/bindings/matrix-sdk-ffi/src/platform/rolling_writer.rs @@ -237,12 +237,11 @@ impl SizeAndDateRollingWriter { check_conditions: bool, ) -> io::Result<()> { // Check if rotation is needed (skip for uninitialized state) - if check_conditions { - if let Some(state) = state.as_ref() { - if !Self::should_rotate_by_time(config, &state.current_path) { - return Ok(()); - } - } + if check_conditions + && let Some(state) = state.as_ref() + && !Self::should_rotate_by_time(config, &state.current_path) + { + return Ok(()); } let time_str = Self::format_rotation_timestamp(config); @@ -312,10 +311,10 @@ impl SizeAndDateRollingWriter { } // Check if file is older than max age - if let Ok(duration) = now.duration_since(modified) { - if duration.as_secs() > config.max_age_seconds { - let _ = fs::remove_file(path); - } + if let Ok(duration) = now.duration_since(modified) + && duration.as_secs() > config.max_age_seconds + { + let _ = fs::remove_file(path); } } @@ -868,10 +867,10 @@ mod tests { std::fs::read_dir(log_path) .unwrap() .filter(|entry| { - if let Ok(entry) = entry { - if let Some(name) = entry.file_name().to_str() { - return name.starts_with("multi"); - } + if let Ok(entry) = entry + && let Some(name) = entry.file_name().to_str() + { + return name.starts_with("multi"); } false }) diff --git a/bindings/matrix-sdk-ffi/src/room/mod.rs b/bindings/matrix-sdk-ffi/src/room/mod.rs index 330cd3d40..3e21d7b34 100644 --- a/bindings/matrix-sdk-ffi/src/room/mod.rs +++ b/bindings/matrix-sdk-ffi/src/room/mod.rs @@ -1212,12 +1212,11 @@ impl Room { // If no server names are provided and the room's membership is invited, // add the server name from the sender's user id as a fallback value - if server_names.is_empty() { - if let Ok(invite_details) = self.inner.invite_details().await { - if let Some(inviter) = invite_details.inviter { - server_names.push(inviter.user_id().server_name().to_owned()); - } - } + if server_names.is_empty() + && let Ok(invite_details) = self.inner.invite_details().await + && let Some(inviter) = invite_details.inviter + { + server_names.push(inviter.user_id().server_name().to_owned()); } let room_preview = client.get_room_preview(&room_or_alias_id, server_names).await?; diff --git a/bindings/matrix-sdk-ffi/src/session_verification.rs b/bindings/matrix-sdk-ffi/src/session_verification.rs index 1e16e8e57..ec143f342 100644 --- a/bindings/matrix-sdk-ffi/src/session_verification.rs +++ b/bindings/matrix-sdk-ffi/src/session_verification.rs @@ -246,16 +246,15 @@ impl SessionVerificationController { sender: &UserId, flow_id: impl AsRef, ) { - if sender != self.user_identity.user_id() { - if let Some(status) = self.encryption.cross_signing_status().await { - if !status.is_complete() { - warn!( - "Cannot verify other users until our own device's cross-signing status \ - is complete: {status:?}" - ); - return; - } - } + if sender != self.user_identity.user_id() + && let Some(status) = self.encryption.cross_signing_status().await + && !status.is_complete() + { + warn!( + "Cannot verify other users until our own device's cross-signing status \ + is complete: {status:?}" + ); + return; } let Some(request) = self.encryption.get_verification_request(sender, flow_id).await else { @@ -290,15 +289,10 @@ impl SessionVerificationController { ) -> Result<(), ClientError> { if let Some(ongoing_verification_request) = self.verification_request.read().unwrap().clone() + && !ongoing_verification_request.is_done() + && !ongoing_verification_request.is_cancelled() { - if !ongoing_verification_request.is_done() - && !ongoing_verification_request.is_cancelled() - { - return Err(ClientError::from_str( - "There is another verification flow ongoing.", - None, - )); - } + return Err(ClientError::from_str("There is another verification flow ongoing.", None)); } *self.verification_request.write().unwrap() = Some(verification_request.clone()); diff --git a/bindings/matrix-sdk-ffi/src/utd.rs b/bindings/matrix-sdk-ffi/src/utd.rs index 64ac6645a..39e853b3e 100644 --- a/bindings/matrix-sdk-ffi/src/utd.rs +++ b/bindings/matrix-sdk-ffi/src/utd.rs @@ -41,10 +41,10 @@ impl UnableToDecryptHook for UtdHook { // UTDs that have been decrypted in the `IGNORE_UTD_PERIOD` are just ignored and // not considered UTDs. - if let Some(duration) = &info.time_to_decrypt { - if *duration < IGNORE_UTD_PERIOD { - return; - } + if let Some(duration) = &info.time_to_decrypt + && *duration < IGNORE_UTD_PERIOD + { + return; } // Report the UTD to the client.