From 7b056735ed1f2fdc15a1e7b2bfe0375d21bbfbdc Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Fri, 4 Aug 2023 11:25:02 +0000 Subject: [PATCH] rust/pv: some `cargo clippy` fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found and fixed by the command `cargo clippy --fix -- -Dwarnings`. Reviewed-by: Jan Höppner Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- rust/pv/src/utils.rs | 8 ++++---- rust/pv/src/uvdevice/test.rs | 11 +++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/rust/pv/src/utils.rs b/rust/pv/src/utils.rs index 33bcd4d0..13dda2aa 100644 --- a/rust/pv/src/utils.rs +++ b/rust/pv/src/utils.rs @@ -527,15 +527,15 @@ mod tests { fn parse_hex() { let s = "123456acbef0"; let exp = vec![0x12, 0x34, 0x56, 0xac, 0xbe, 0xf0]; - assert_eq!(super::parse_hex(&s), exp); + assert_eq!(super::parse_hex(s), exp); let s = "00123456acbef0"; let exp = vec![0, 0x12, 0x34, 0x56, 0xac, 0xbe, 0xf0]; - assert_eq!(super::parse_hex(&s), exp); + assert_eq!(super::parse_hex(s), exp); let s = "00123456acbef0ii90"; let exp = vec![0, 0x12, 0x34, 0x56, 0xac, 0xbe, 0xf0]; - assert_eq!(super::parse_hex(&s), exp); + assert_eq!(super::parse_hex(s), exp); } #[test] @@ -653,6 +653,6 @@ mod tests { assert!(super::memeq(&a, &a.clone())); assert!(!super::memeq(&b, &a)); assert!(!super::memeq(&b, &c)); - assert!(!super::memeq(&b, &vec![])); + assert!(!super::memeq(&b, &[])); } } diff --git a/rust/pv/src/uvdevice/test.rs b/rust/pv/src/uvdevice/test.rs index c34c2946..0d67a3d8 100644 --- a/rust/pv/src/uvdevice/test.rs +++ b/rust/pv/src/uvdevice/test.rs @@ -61,7 +61,6 @@ impl IoctlCtx { pub mod mock_libc { use super::*; - use std::mem::transmute; pub unsafe fn ioctl( fd: ::libc::c_int, @@ -75,7 +74,7 @@ pub mod mock_libc { assert_eq!(cmd, ctx.exp_cmd, "IOCTL cmd mismatch"); assert_eq!(fd, 17, "IOCTL fd mismatch"); - let data_ref: &mut ffi::uvio_ioctl_cb = transmute(data); + let data_ref: &mut ffi::uvio_ioctl_cb = &mut *data; (ctx.modify)(data_ref) } @@ -194,11 +193,7 @@ fn ioctl_write_data() { get_lock(&IOCTL_MTX).exp_cmd(TEST_CMD).set_mdfy(move |cb| { cb.set_rc(1).addr_eq(data_addr).size_eq(32); unsafe { - ::libc::memset( - (*cb).argument_addr as *mut ::libc::c_void, - 0x42, - cmd_data_len, - ); + ::libc::memset(cb.argument_addr as *mut ::libc::c_void, 0x42, cmd_data_len); } 0 }); @@ -223,7 +218,7 @@ fn ioctl_read_data() { get_lock(&IOCTL_MTX).exp_cmd(TEST_CMD).set_mdfy(move |cb| { cb.set_rc(1).addr_eq(data_addr).size_eq(32); unsafe { - let data = std::slice::from_raw_parts((*cb).argument_addr as *const u8, cmd_data_len); + let data = std::slice::from_raw_parts(cb.argument_addr as *const u8, cmd_data_len); assert_eq!(data, data_exp); } 0