From 17b0d519a89cd2271ec1a4455f7a0e393eef2022 Mon Sep 17 00:00:00 2001 From: Flawed <33593723+ff14wed@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:52:16 -0700 Subject: [PATCH] Fix clippy warnings --- deucalion/src/hook/mod.rs | 4 ++-- deucalion/src/procloader.rs | 6 +++--- deucalion/src/rpc.rs | 4 ++-- deucalion/src/server.rs | 21 ++++++++++----------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/deucalion/src/hook/mod.rs b/deucalion/src/hook/mod.rs index 98b3106..2e03da2 100644 --- a/deucalion/src/hook/mod.rs +++ b/deucalion/src/hook/mod.rs @@ -37,14 +37,14 @@ pub enum HookType { #[repr(u32)] #[derive(Debug, Clone, Copy)] -pub(self) enum Channel { +enum Channel { Lobby, Zone, Chat, } #[derive(Debug, Error)] -pub(self) enum HookError { +enum HookError { #[error("number of signature matches is incorrect: {0} != {1}")] SignatureMatchFailed(usize, usize), } diff --git a/deucalion/src/procloader.rs b/deucalion/src/procloader.rs index cf46dd9..69dadc9 100644 --- a/deucalion/src/procloader.rs +++ b/deucalion/src/procloader.rs @@ -71,9 +71,9 @@ pub fn get_ffxiv_filepath() -> Result { /// * `pat` - pattern to match /// * `pe` - the PE to search through /// * `save` - each level of the result is saved as additional entries in this -/// array +/// array /// * `search_start_rva` - Optionally specify that the search range starts at a -/// different relative virtual address. Set to 0 for starting at the beginning. +/// different relative virtual address. Set to 0 for starting at the beginning. pub fn fast_pattern_scan<'a, P: Pe<'a>>( pat: &[pat::Atom], pe: P, @@ -298,7 +298,7 @@ mod tests { #[test] fn test_incorrect_pat_len() { - if let Ok(_) = get_pat_len_and_excerpt(BAD_SIG) { + if get_pat_len_and_excerpt(BAD_SIG).is_ok() { panic!("Bad sig should return error"); } } diff --git a/deucalion/src/rpc.rs b/deucalion/src/rpc.rs index ee4da1b..b528a03 100644 --- a/deucalion/src/rpc.rs +++ b/deucalion/src/rpc.rs @@ -164,8 +164,8 @@ mod tests { let payload_op = payload.op as u8; codec.encode(payload, &mut buf).unwrap(); let expected: &[u8] = &[12, 0, 0, 0, payload_op, 100, 0, 0, 0, 1, 2, 3]; - let mut dst: &mut [u8] = &mut [0; 12]; - buf.copy_to_slice(&mut dst); + let dst: &mut [u8] = &mut [0; 12]; + buf.copy_to_slice(dst); assert_eq!(dst, expected); } } diff --git a/deucalion/src/server.rs b/deucalion/src/server.rs index fd65843..385e803 100644 --- a/deucalion/src/server.rs +++ b/deucalion/src/server.rs @@ -524,7 +524,7 @@ mod tests { use std::sync::atomic::{AtomicU32, Ordering}; use super::*; - use ntest::timeout; + use ntest::{assert_false, assert_true, timeout}; use rand::Rng; use tokio::{select, task::JoinHandle}; @@ -544,9 +544,9 @@ mod tests { const ALLOW_EVERYTHING: u32 = 0xFF; for (filter, op, ctx) in configurations { let filter = filter as u32; - assert_eq!(allow_broadcast(op, ctx, ALLOW_EVERYTHING), true); - assert_eq!(allow_broadcast(op, ctx, filter), true); - assert_eq!(allow_broadcast(op, ctx, ALLOW_EVERYTHING & !filter), false); + assert_true!(allow_broadcast(op, ctx, ALLOW_EVERYTHING)); + assert_true!(allow_broadcast(op, ctx, filter)); + assert_false!(allow_broadcast(op, ctx, ALLOW_EVERYTHING & !filter)); } } @@ -573,7 +573,7 @@ mod tests { ), ]; for (nickname, expected_err) in nickname_tests { - match validate_nickname(&nickname.to_string()) { + match validate_nickname(nickname) { Ok(()) => { if let Some(err_msg) = expected_err { panic!("Expected validation for {nickname} to error with {err_msg}"); @@ -718,10 +718,10 @@ mod tests { select! { data = frames.next() => { - assert_eq!(should_be_allowed, true, "packet should be filtered: {:?}", data); + assert!(should_be_allowed, "packet should be filtered: {:?}", data); } _ = time::sleep(Duration::from_millis(100)) => { - assert_eq!(should_be_allowed, false, "packet should not be filtered: {:?}: {}", op, ctx) + assert!(!should_be_allowed, "packet should not be filtered: {:?}: {}", op, ctx) } } } @@ -849,8 +849,7 @@ mod tests { handle_server_hello(&mut frames).await; - let subscriber_handle = - tokio::spawn(async move { while let Some(_) = frames.next().await {} }); + let subscriber_handle = tokio::spawn(async move { while frames.next().await.is_some() {} }); // Disconnect the subscriber forcefully subscriber_handle.abort(); @@ -899,7 +898,7 @@ mod tests { let codec = PayloadCodec::new(); let mut frames = Framed::new(subscriber, codec); - while let Some(_) = frames.next().await {} + while frames.next().await.is_some() {} }); second_subscriber.abort(); @@ -994,7 +993,7 @@ mod tests { if let Ok(subscriber) = Endpoint::connect(&pipe_name_clone).await { let codec = PayloadCodec::new(); let mut frames = Framed::new(subscriber, codec); - while let Some(_) = frames.next().await {} + while frames.next().await.is_some() {} } }); sub_handle.abort();