From f036e3d265ea19139e1510b410a63b2e648ac7bf Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 4 Oct 2024 09:28:42 -0500 Subject: [PATCH] Address Rust nightly compiler warnings (#3311) --- crates/libs/bindgen/src/tokens/runtime.rs | 4 +-- crates/libs/bindgen/src/tokens/to_tokens.rs | 6 ++-- crates/libs/core/src/interface.rs | 10 +++--- crates/libs/core/src/out_ref.rs | 2 +- crates/libs/core/src/ref.rs | 4 +-- crates/libs/core/src/scoped_interface.rs | 6 ++-- crates/libs/registry/src/key_iterator.rs | 2 +- crates/libs/registry/src/value_iterator.rs | 2 +- crates/libs/strings/src/bstr.rs | 2 +- crates/libs/strings/src/hstring.rs | 4 +-- crates/tests/misc/array/tests/primitive.rs | 2 +- crates/tests/misc/bcrypt/tests/sys.rs | 3 +- crates/tests/misc/bcrypt/tests/win.rs | 3 +- .../misc/calling_convention/tests/sys.rs | 2 +- .../tests/misc/class_hierarchy/tests/tests.rs | 4 +-- crates/tests/misc/error/tests/test.rs | 24 +++++++------- crates/tests/misc/extensions/tests/bool32.rs | 8 ++--- crates/tests/misc/extensions/tests/boolean.rs | 8 ++--- .../tests/misc/extensions/tests/ntstatus.rs | 18 +++++------ .../misc/extensions/tests/variant_bool.rs | 8 ++--- crates/tests/misc/handles/tests/legacy.rs | 6 ++-- crates/tests/misc/handles/tests/win.rs | 4 +-- .../misc/implement/tests/generic_default.rs | 12 +++---- .../misc/implement/tests/generic_primitive.rs | 2 +- .../tests/misc/implement/tests/into_impl.rs | 30 +++++++++--------- crates/tests/misc/implement/tests/vector.rs | 31 +++++++++---------- crates/tests/misc/sys/tests/simple.rs | 2 +- crates/tests/misc/variant/tests/tests.rs | 8 ++--- crates/tests/misc/win32/tests/win32.rs | 6 ++-- .../winrt/collections/tests/stock_map_view.rs | 10 +++--- .../collections/tests/stock_vector_view.rs | 10 +++--- 31 files changed, 120 insertions(+), 123 deletions(-) diff --git a/crates/libs/bindgen/src/tokens/runtime.rs b/crates/libs/bindgen/src/tokens/runtime.rs index 83bc42a040..b5b9270fd8 100644 --- a/crates/libs/bindgen/src/tokens/runtime.rs +++ b/crates/libs/bindgen/src/tokens/runtime.rs @@ -80,7 +80,7 @@ pub mod ext { fn quote_into_iter(&'q self) -> (Self::Iter, HasIter); } - impl<'q, 'a, T: RepAsIteratorExt<'q> + ?Sized> RepAsIteratorExt<'q> for &'a T { + impl<'q, T: RepAsIteratorExt<'q> + ?Sized> RepAsIteratorExt<'q> for &T { type Iter = T::Iter; fn quote_into_iter(&'q self) -> (Self::Iter, HasIter) { @@ -88,7 +88,7 @@ pub mod ext { } } - impl<'q, 'a, T: RepAsIteratorExt<'q> + ?Sized> RepAsIteratorExt<'q> for &'a mut T { + impl<'q, T: RepAsIteratorExt<'q> + ?Sized> RepAsIteratorExt<'q> for &mut T { type Iter = T::Iter; fn quote_into_iter(&'q self) -> (Self::Iter, HasIter) { diff --git a/crates/libs/bindgen/src/tokens/to_tokens.rs b/crates/libs/bindgen/src/tokens/to_tokens.rs index cb614f33d7..9b916742bf 100644 --- a/crates/libs/bindgen/src/tokens/to_tokens.rs +++ b/crates/libs/bindgen/src/tokens/to_tokens.rs @@ -32,19 +32,19 @@ pub trait ToTokens { } } -impl<'a, T: ?Sized + ToTokens> ToTokens for &'a T { +impl ToTokens for &T { fn to_tokens(&self, tokens: &mut TokenStream) { (**self).to_tokens(tokens); } } -impl<'a, T: ?Sized + ToTokens> ToTokens for &'a mut T { +impl ToTokens for &mut T { fn to_tokens(&self, tokens: &mut TokenStream) { (**self).to_tokens(tokens); } } -impl<'a, T: ?Sized + ToOwned + ToTokens> ToTokens for Cow<'a, T> { +impl ToTokens for Cow<'_, T> { fn to_tokens(&self, tokens: &mut TokenStream) { (**self).to_tokens(tokens); } diff --git a/crates/libs/core/src/interface.rs b/crates/libs/core/src/interface.rs index 7b2a231e42..b36ed7d5c1 100644 --- a/crates/libs/core/src/interface.rs +++ b/crates/libs/core/src/interface.rs @@ -272,21 +272,21 @@ pub unsafe fn from_raw_borrowed(raw: &*mut c_void) -> Option<&T> { #[repr(transparent)] pub struct InterfaceRef<'a, I>(NonNull, PhantomData<&'a I>); -impl<'a, I> Copy for InterfaceRef<'a, I> {} +impl Copy for InterfaceRef<'_, I> {} -impl<'a, I> Clone for InterfaceRef<'a, I> { +impl Clone for InterfaceRef<'_, I> { fn clone(&self) -> Self { *self } } -impl<'a, I: core::fmt::Debug + Interface> core::fmt::Debug for InterfaceRef<'a, I> { +impl core::fmt::Debug for InterfaceRef<'_, I> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { ::fmt(&**self, f) } } -impl<'a, I: Interface> InterfaceRef<'a, I> { +impl InterfaceRef<'_, I> { /// Creates an `InterfaceRef` from a raw pointer. _This is extremely dangerous, since there /// is no lifetime tracking at all!_ /// @@ -325,7 +325,7 @@ impl<'a, 'i: 'a, I: Interface> From<&'i I> for InterfaceRef<'a, I> { } } -impl<'a, I: Interface> core::ops::Deref for InterfaceRef<'a, I> { +impl core::ops::Deref for InterfaceRef<'_, I> { type Target = I; #[inline(always)] diff --git a/crates/libs/core/src/out_ref.rs b/crates/libs/core/src/out_ref.rs index 725b84c2e9..d9ecb7931c 100644 --- a/crates/libs/core/src/out_ref.rs +++ b/crates/libs/core/src/out_ref.rs @@ -6,7 +6,7 @@ use super::*; #[repr(transparent)] pub struct OutRef<'a, T: Type>(*mut T::Abi, core::marker::PhantomData<&'a T>); -impl<'a, T: Type> OutRef<'a, T> { +impl> OutRef<'_, T> { /// Returns `true` if the argument is null. pub fn is_null(&self) -> bool { self.0.is_null() diff --git a/crates/libs/core/src/ref.rs b/crates/libs/core/src/ref.rs index 4c270d5477..fb40e8ff3f 100644 --- a/crates/libs/core/src/ref.rs +++ b/crates/libs/core/src/ref.rs @@ -7,7 +7,7 @@ use core::mem::transmute; #[repr(transparent)] pub struct Ref<'a, T: Type>(T::Abi, PhantomData<&'a T>); -impl<'a, T: Type, Abi = *mut c_void>> Ref<'a, T> { +impl, Abi = *mut c_void>> Ref<'_, T> { /// Converts the argument to a [Result<&T>] reference. pub fn ok(&self) -> Result<&T> { if self.0.is_null() { @@ -18,7 +18,7 @@ impl<'a, T: Type, Abi = *mut c_void>> Ref<'a, T> { } } -impl<'a, T: Type> core::ops::Deref for Ref<'a, T> { +impl> core::ops::Deref for Ref<'_, T> { type Target = T::Default; fn deref(&self) -> &Self::Target { unsafe { transmute(&self.0) } diff --git a/crates/libs/core/src/scoped_interface.rs b/crates/libs/core/src/scoped_interface.rs index 09f9298978..5a701e8cee 100644 --- a/crates/libs/core/src/scoped_interface.rs +++ b/crates/libs/core/src/scoped_interface.rs @@ -15,7 +15,7 @@ pub struct ScopedInterface<'a, T: Interface> { lifetime: PhantomData<&'a T>, } -impl<'a, T: Interface> ScopedInterface<'a, T> { +impl ScopedInterface<'_, T> { pub fn new(interface: T) -> Self { Self { interface, @@ -24,7 +24,7 @@ impl<'a, T: Interface> ScopedInterface<'a, T> { } } -impl<'a, T: Interface> core::ops::Deref for ScopedInterface<'a, T> { +impl core::ops::Deref for ScopedInterface<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -32,7 +32,7 @@ impl<'a, T: Interface> core::ops::Deref for ScopedInterface<'a, T> { } } -impl<'a, T: Interface> Drop for ScopedInterface<'a, T> { +impl Drop for ScopedInterface<'_, T> { fn drop(&mut self) { unsafe { let _ = Box::from_raw(self.interface.as_raw() as *const _ as *mut ScopedHeap); diff --git a/crates/libs/registry/src/key_iterator.rs b/crates/libs/registry/src/key_iterator.rs index aca76c5ff1..df419720da 100644 --- a/crates/libs/registry/src/key_iterator.rs +++ b/crates/libs/registry/src/key_iterator.rs @@ -37,7 +37,7 @@ impl<'a> KeyIterator<'a> { } } -impl<'a> Iterator for KeyIterator<'a> { +impl Iterator for KeyIterator<'_> { type Item = String; fn next(&mut self) -> Option { diff --git a/crates/libs/registry/src/value_iterator.rs b/crates/libs/registry/src/value_iterator.rs index e11d319b5a..1b883f2c61 100644 --- a/crates/libs/registry/src/value_iterator.rs +++ b/crates/libs/registry/src/value_iterator.rs @@ -42,7 +42,7 @@ impl<'a> ValueIterator<'a> { } } -impl<'a> Iterator for ValueIterator<'a> { +impl Iterator for ValueIterator<'_> { type Item = (String, Value); fn next(&mut self) -> Option { diff --git a/crates/libs/strings/src/bstr.rs b/crates/libs/strings/src/bstr.rs index 53cf5da87e..deaed297cb 100644 --- a/crates/libs/strings/src/bstr.rs +++ b/crates/libs/strings/src/bstr.rs @@ -93,7 +93,7 @@ impl From<&String> for BSTR { } } -impl<'a> TryFrom<&'a BSTR> for String { +impl TryFrom<&BSTR> for String { type Error = alloc::string::FromUtf16Error; fn try_from(value: &BSTR) -> core::result::Result { diff --git a/crates/libs/strings/src/hstring.rs b/crates/libs/strings/src/hstring.rs index a72a8dd11a..b4568147c5 100644 --- a/crates/libs/strings/src/hstring.rs +++ b/crates/libs/strings/src/hstring.rs @@ -357,7 +357,7 @@ impl PartialEq<&HSTRING> for std::ffi::OsString { } } -impl<'a> TryFrom<&'a HSTRING> for String { +impl TryFrom<&HSTRING> for String { type Error = alloc::string::FromUtf16Error; fn try_from(hstring: &HSTRING) -> core::result::Result { @@ -374,7 +374,7 @@ impl TryFrom for String { } #[cfg(feature = "std")] -impl<'a> From<&'a HSTRING> for std::ffi::OsString { +impl From<&HSTRING> for std::ffi::OsString { fn from(hstring: &HSTRING) -> Self { hstring.to_os_string() } diff --git a/crates/tests/misc/array/tests/primitive.rs b/crates/tests/misc/array/tests/primitive.rs index b78e20ab59..36ec9cf73c 100644 --- a/crates/tests/misc/array/tests/primitive.rs +++ b/crates/tests/misc/array/tests/primitive.rs @@ -18,7 +18,7 @@ fn array() { assert_eq!(a[1], 2); assert_eq!(a[2], 3); - let result = a.as_slice().iter().fold(0, |acc, x| acc + x); + let result = a.as_slice().iter().sum::(); assert_eq!(result, 6); let a = Array::::from_slice(&[4, 5, 6]); diff --git a/crates/tests/misc/bcrypt/tests/sys.rs b/crates/tests/misc/bcrypt/tests/sys.rs index 440ed7b88f..dde99a0ab5 100644 --- a/crates/tests/misc/bcrypt/tests/sys.rs +++ b/crates/tests/misc/bcrypt/tests/sys.rs @@ -70,8 +70,7 @@ fn test() { let block_len = u32::from_le_bytes(block_len) as usize; let send_message = "I ❤️ Rust"; - let mut send_buffer = - vec![0; block_len * ((send_message.len() + (block_len - 1)) / block_len)]; + let mut send_buffer = vec![0; block_len * send_message.len().div_ceil(block_len)]; send_buffer[..send_message.len()].copy_from_slice(send_message.as_bytes()); let mut encrypted_len = 0; diff --git a/crates/tests/misc/bcrypt/tests/win.rs b/crates/tests/misc/bcrypt/tests/win.rs index 832cc11672..15ef0e68a7 100644 --- a/crates/tests/misc/bcrypt/tests/win.rs +++ b/crates/tests/misc/bcrypt/tests/win.rs @@ -41,8 +41,7 @@ fn test() -> Result<()> { let block_len = u32::from_le_bytes(block_len) as usize; let send_message = "I ❤️ Rust"; - let mut send_buffer = - vec![0; block_len * ((send_message.len() + (block_len - 1)) / block_len)]; + let mut send_buffer = vec![0; block_len * send_message.len().div_ceil(block_len)]; send_buffer[..send_message.len()].copy_from_slice(send_message.as_bytes()); let mut encrypted_len = 0; diff --git a/crates/tests/misc/calling_convention/tests/sys.rs b/crates/tests/misc/calling_convention/tests/sys.rs index bfdb6628b8..547b4a8d1a 100644 --- a/crates/tests/misc/calling_convention/tests/sys.rs +++ b/crates/tests/misc/calling_convention/tests/sys.rs @@ -19,7 +19,7 @@ fn variadic() { unsafe { let mut buffer = vec![0u8; 1024]; let len = wsprintfA(buffer.as_mut_ptr(), s!("test-%d-%d!"), 123u32, 456u32); - let result = std::str::from_utf8_unchecked(&std::slice::from_raw_parts( + let result = std::str::from_utf8_unchecked(std::slice::from_raw_parts( buffer.as_ptr(), len as usize, )); diff --git a/crates/tests/misc/class_hierarchy/tests/tests.rs b/crates/tests/misc/class_hierarchy/tests/tests.rs index 351edf4c03..64b03abe34 100644 --- a/crates/tests/misc/class_hierarchy/tests/tests.rs +++ b/crates/tests/misc/class_hierarchy/tests/tests.rs @@ -30,9 +30,9 @@ fn call_interface(b: &IMemoryBuffer) -> Result<()> { } fn as_class>(b: P) -> Result<()> { - unsafe { call_class(&b.param().borrow().as_ref().unwrap()) } + unsafe { call_class(b.param().borrow().as_ref().unwrap()) } } fn as_interface>(b: P) -> Result<()> { - unsafe { call_interface(&b.param().borrow().as_ref().unwrap()) } + unsafe { call_interface(b.param().borrow().as_ref().unwrap()) } } diff --git a/crates/tests/misc/error/tests/test.rs b/crates/tests/misc/error/tests/test.rs index fdcc2339ed..271dfc8710 100644 --- a/crates/tests/misc/error/tests/test.rs +++ b/crates/tests/misc/error/tests/test.rs @@ -7,10 +7,10 @@ fn hresult() -> Result<()> { let error: Error = E_INVALIDARG.into(); assert_eq!(error.code(), E_INVALIDARG); - assert_eq!(E_INVALIDARG.is_ok(), false); - assert_eq!(E_INVALIDARG.is_err(), true); - assert_eq!(S_OK.is_ok(), true); - assert_eq!(S_OK.is_err(), false); + assert!(!E_INVALIDARG.is_ok()); + assert!(E_INVALIDARG.is_err()); + assert!(S_OK.is_ok()); + assert!(!S_OK.is_err()); assert_eq!(format!("{S_OK:?}"), "HRESULT(0x00000000)"); assert_eq!(format!("{E_INVALIDARG:?}"), "HRESULT(0x80070057)"); @@ -27,10 +27,10 @@ fn win32_error() -> Result<()> { assert_eq!(error.code(), hresult); assert_eq!(WIN32_ERROR::from_error(&error), Some(ERROR_BAD_ARGUMENTS)); - assert_eq!(ERROR_BAD_ARGUMENTS.is_ok(), false); - assert_eq!(ERROR_BAD_ARGUMENTS.is_err(), true); - assert_eq!(ERROR_SUCCESS.is_ok(), true); - assert_eq!(ERROR_SUCCESS.is_err(), false); + assert!(!ERROR_BAD_ARGUMENTS.is_ok()); + assert!(ERROR_BAD_ARGUMENTS.is_err()); + assert!(ERROR_SUCCESS.is_ok()); + assert!(!ERROR_SUCCESS.is_err()); assert_eq!(format!("{ERROR_SUCCESS:?}"), "WIN32_ERROR(0)"); assert_eq!(format!("{ERROR_BAD_ARGUMENTS:?}"), "WIN32_ERROR(160)"); @@ -47,10 +47,10 @@ fn ntstatus() -> Result<()> { assert_eq!(error.code(), hresult); assert_eq!(error.message(), "The object was not found."); - assert_eq!(STATUS_NOT_FOUND.is_ok(), false); - assert_eq!(STATUS_NOT_FOUND.is_err(), true); - assert_eq!(STATUS_SUCCESS.is_ok(), true); - assert_eq!(STATUS_SUCCESS.is_err(), false); + assert!(!STATUS_NOT_FOUND.is_ok()); + assert!(STATUS_NOT_FOUND.is_err()); + assert!(STATUS_SUCCESS.is_ok()); + assert!(!STATUS_SUCCESS.is_err()); assert_eq!(format!("{STATUS_SUCCESS:?}"), "NTSTATUS(0)"); assert_eq!(format!("{STATUS_NOT_FOUND:?}"), "NTSTATUS(-1073741275)"); diff --git a/crates/tests/misc/extensions/tests/bool32.rs b/crates/tests/misc/extensions/tests/bool32.rs index e3c5ce17c1..848e7c46ce 100644 --- a/crates/tests/misc/extensions/tests/bool32.rs +++ b/crates/tests/misc/extensions/tests/bool32.rs @@ -7,17 +7,17 @@ fn test() { let status = BOOL(1); assert_eq!(status.0, 1); - assert_eq!(status.as_bool(), true); - assert_eq!(status.ok().is_ok(), true); + assert!(status.as_bool()); + assert!(status.ok().is_ok()); unsafe { SetLastError(ERROR_ACCESS_DENIED); } let status = BOOL(0); assert_eq!(status.0, 0); - assert_eq!(status.as_bool(), false); + assert!(!status.as_bool()); let result = status.ok(); - assert_eq!(result.is_ok(), false); + assert!(!result.is_ok()); let error = result.unwrap_err(); assert_eq!(error.code(), E_ACCESSDENIED); } diff --git a/crates/tests/misc/extensions/tests/boolean.rs b/crates/tests/misc/extensions/tests/boolean.rs index 06e4c556e2..2b9727a307 100644 --- a/crates/tests/misc/extensions/tests/boolean.rs +++ b/crates/tests/misc/extensions/tests/boolean.rs @@ -7,17 +7,17 @@ fn test() { let status = BOOLEAN(1); assert_eq!(status.0, 1); - assert_eq!(status.as_bool(), true); - assert_eq!(status.ok().is_ok(), true); + assert!(status.as_bool()); + assert!(status.ok().is_ok()); unsafe { SetLastError(ERROR_ACCESS_DENIED); } let status = BOOLEAN(0); assert_eq!(status.0, 0); - assert_eq!(status.as_bool(), false); + assert!(!status.as_bool()); let result = status.ok(); - assert_eq!(result.is_ok(), false); + assert!(!result.is_ok()); let error = result.unwrap_err(); assert_eq!(error.code(), E_ACCESSDENIED); } diff --git a/crates/tests/misc/extensions/tests/ntstatus.rs b/crates/tests/misc/extensions/tests/ntstatus.rs index 8f9f46f625..04d309c65e 100644 --- a/crates/tests/misc/extensions/tests/ntstatus.rs +++ b/crates/tests/misc/extensions/tests/ntstatus.rs @@ -4,15 +4,15 @@ use windows::{core::*, Win32::Foundation::*, Win32::Security::Cryptography::*}; fn test() -> Result<()> { let status = NTSTATUS::default(); assert_eq!(status.0, 0); - assert_eq!(status.is_ok(), true); - assert_eq!(status.is_err(), false); - assert_eq!(status.ok().is_ok(), true); + assert!(status.is_ok()); + assert!(!status.is_err()); + assert!(status.ok().is_ok()); let status = STATUS_NOT_FOUND; assert_eq!(status.0, -1073741275); - assert_eq!(status.is_ok(), false); - assert_eq!(status.is_err(), true); - assert_eq!(status.ok().is_ok(), false); + assert!(!status.is_ok()); + assert!(status.is_err()); + assert!(!status.ok().is_ok()); let error = status.ok().unwrap_err(); assert_eq!(error.code(), HRESULT(-805305819)); @@ -64,9 +64,9 @@ fn is_valid(status: NTSTATUS) -> Result { #[test] fn test_verify() -> Result<()> { - assert_eq!(is_valid(STATUS_SUCCESS)?, true); - assert_eq!(is_valid(STATUS_INVALID_SIGNATURE)?, false); - assert_eq!(is_valid(STATUS_NOT_FOUND).is_err(), true); + assert!(is_valid(STATUS_SUCCESS)?); + assert!(!(is_valid(STATUS_INVALID_SIGNATURE)?)); + assert!(is_valid(STATUS_NOT_FOUND).is_err()); Ok(()) } diff --git a/crates/tests/misc/extensions/tests/variant_bool.rs b/crates/tests/misc/extensions/tests/variant_bool.rs index 7a8007b288..28a446fde9 100644 --- a/crates/tests/misc/extensions/tests/variant_bool.rs +++ b/crates/tests/misc/extensions/tests/variant_bool.rs @@ -7,17 +7,17 @@ fn test() { let status = VARIANT_TRUE; assert_eq!(status.0, -1); - assert_eq!(status.as_bool(), true); - assert_eq!(status.ok().is_ok(), true); + assert!(status.as_bool()); + assert!(status.ok().is_ok()); unsafe { SetLastError(ERROR_ACCESS_DENIED); } let status = VARIANT_FALSE; assert_eq!(status.0, 0); - assert_eq!(status.as_bool(), false); + assert!(!status.as_bool()); let result = status.ok(); - assert_eq!(result.is_ok(), false); + assert!(!result.is_ok()); let error = result.unwrap_err(); assert_eq!(error.code(), E_ACCESSDENIED); } diff --git a/crates/tests/misc/handles/tests/legacy.rs b/crates/tests/misc/handles/tests/legacy.rs index 88aa1b66f2..6883bd46f4 100644 --- a/crates/tests/misc/handles/tests/legacy.rs +++ b/crates/tests/misc/handles/tests/legacy.rs @@ -5,7 +5,7 @@ use windows::Win32::System::Registry::*; #[test] fn handle() { let handle = HANDLE(0 as _); - let _clone = handle.clone(); + let _clone = handle; let _copy: HANDLE = handle; assert!(HANDLE::default() == HANDLE(0 as _)); assert!(HANDLE(0 as _).is_invalid()); @@ -24,7 +24,7 @@ fn boolean() { #[test] fn pstr() { let handle = PSTR(core::ptr::null_mut()); - let _clone = handle.clone(); + let _clone = handle; let _copy: PSTR = handle; assert!(handle.is_null()); } @@ -32,7 +32,7 @@ fn pstr() { #[test] fn pwstr() { let handle = PWSTR::null(); - let _clone = handle.clone(); + let _clone = handle; let _copy: PWSTR = handle; assert!(handle.is_null()); } diff --git a/crates/tests/misc/handles/tests/win.rs b/crates/tests/misc/handles/tests/win.rs index abc1517c93..d341ed0b1c 100644 --- a/crates/tests/misc/handles/tests/win.rs +++ b/crates/tests/misc/handles/tests/win.rs @@ -13,7 +13,7 @@ fn handle() { let copy = handle; assert!(copy == handle); - let clone = handle.clone(); + let clone = handle; assert!(clone == handle); let default = HANDLE::default(); @@ -31,7 +31,7 @@ fn psid() { let copy = handle; assert!(copy == handle); - let clone = handle.clone(); + let clone = handle; assert!(clone == handle); let default = PSID::default(); diff --git a/crates/tests/misc/implement/tests/generic_default.rs b/crates/tests/misc/implement/tests/generic_default.rs index 0a931282f9..b79c380939 100644 --- a/crates/tests/misc/implement/tests/generic_default.rs +++ b/crates/tests/misc/implement/tests/generic_default.rs @@ -63,11 +63,11 @@ fn test_implement() -> Result<()> { assert_eq!(3, v.Size()?); let mut index = 0; - assert_eq!(true, v.IndexOf(20, &mut index)?); + assert!(v.IndexOf(20, &mut index)?); assert_eq!(1, index); - assert_eq!(true, v.IndexOf(30, &mut index)?); + assert!(v.IndexOf(30, &mut index)?); assert_eq!(2, index); - assert_eq!(false, v.IndexOf(123, &mut index)?); + assert!(!(v.IndexOf(123, &mut index)?)); let v: IVectorView = Thing(vec!["10".into(), "20".into(), "30".into()]).into(); assert_eq!("10", v.GetAt(0)?); @@ -76,11 +76,11 @@ fn test_implement() -> Result<()> { assert_eq!(3, v.Size()?); let mut index = 0; - assert_eq!(true, v.IndexOf(&HSTRING::from("20"), &mut index)?); + assert!(v.IndexOf(&HSTRING::from("20"), &mut index)?); assert_eq!(1, index); - assert_eq!(true, v.IndexOf(&HSTRING::from("30"), &mut index)?); + assert!(v.IndexOf(&HSTRING::from("30"), &mut index)?); assert_eq!(2, index); - assert_eq!(false, v.IndexOf(&HSTRING::from("123"), &mut index)?); + assert!(!(v.IndexOf(&HSTRING::from("123"), &mut index)?)); let url1: HSTRING = "http://one/".into(); let url2: HSTRING = "http://two/".into(); diff --git a/crates/tests/misc/implement/tests/generic_primitive.rs b/crates/tests/misc/implement/tests/generic_primitive.rs index 480d97323e..82ba52c39a 100644 --- a/crates/tests/misc/implement/tests/generic_primitive.rs +++ b/crates/tests/misc/implement/tests/generic_primitive.rs @@ -41,7 +41,7 @@ fn test_implement() -> Result<()> { assert_eq!(012, v.GetAt(012)?); assert_eq!(123, v.Size()?); let mut index = 0; - assert_eq!(true, v.IndexOf(456, &mut index)?); + assert!(v.IndexOf(456, &mut index)?); assert_eq!(456, index); Ok(()) diff --git a/crates/tests/misc/implement/tests/into_impl.rs b/crates/tests/misc/implement/tests/into_impl.rs index 48a2ac01de..30d97bde20 100644 --- a/crates/tests/misc/implement/tests/into_impl.rs +++ b/crates/tests/misc/implement/tests/into_impl.rs @@ -94,34 +94,34 @@ fn test_explicit() -> Result<()> { let it1 = iterable.First()?; assert_eq!(it1.Current()?, 10); - assert_eq!(it1.HasCurrent()?, true); - assert_eq!(it1.MoveNext()?, true); + assert!(it1.HasCurrent()?); + assert!(it1.MoveNext()?); assert_eq!(it1.Current()?, 20); - assert_eq!(it1.HasCurrent()?, true); - assert_eq!(it1.MoveNext()?, true); + assert!(it1.HasCurrent()?); + assert!(it1.MoveNext()?); assert_eq!(it1.Current()?, 30); - assert_eq!(it1.HasCurrent()?, true); - assert_eq!(it1.MoveNext()?, false); + assert!(it1.HasCurrent()?); + assert!(!(it1.MoveNext()?)); - assert_eq!(it1.Current().is_err(), true); - assert_eq!(it1.HasCurrent()?, false); - assert_eq!(it1.MoveNext()?, false); + assert!(it1.Current().is_err()); + assert!(!(it1.HasCurrent()?)); + assert!(!(it1.MoveNext()?)); // The following just validates that iterators are independent and stable. let it2 = iterable.First()?; assert_eq!(it2.Current()?, 10); - assert_eq!(it2.HasCurrent()?, true); - assert_eq!(it1.Current().is_err(), true); - assert_eq!(it1.HasCurrent()?, false); + assert!(it2.HasCurrent()?); + assert!(it1.Current().is_err()); + assert!(!(it1.HasCurrent()?)); assert_eq!(it2.Current()?, 10); - assert_eq!(it2.HasCurrent()?, true); - assert_eq!(it1.Current().is_err(), true); - assert_eq!(it1.HasCurrent()?, false); + assert!(it2.HasCurrent()?); + assert!(it1.Current().is_err()); + assert!(!(it1.HasCurrent()?)); Ok(()) } diff --git a/crates/tests/misc/implement/tests/vector.rs b/crates/tests/misc/implement/tests/vector.rs index 9c3c2e03a5..c2ae2d58ee 100644 --- a/crates/tests/misc/implement/tests/vector.rs +++ b/crates/tests/misc/implement/tests/vector.rs @@ -94,7 +94,7 @@ where } else { let len = writer.len(); writer.try_reserve(len + 1).map_err(|_| err_memory())?; - writer.insert(index as usize, value.clone()); + writer.insert(index, value.clone()); Ok(()) } } @@ -202,24 +202,23 @@ fn Size() -> Result<()> { fn IndexOf() -> Result<()> { let v: IVector = Vector::new(vec![123, 456]).into(); let mut index = 0; - assert_eq!(v.IndexOf(123, &mut index)?, true); + assert!(v.IndexOf(123, &mut index)?); assert_eq!(index, 0); - assert_eq!(v.IndexOf(456, &mut index)?, true); + assert!(v.IndexOf(456, &mut index)?); assert_eq!(index, 1); - assert_eq!(v.IndexOf(789, &mut index)?, false); + assert!(!(v.IndexOf(789, &mut index)?)); let uri = Uri::CreateUri(&HSTRING::from("http://test/"))?; let v: IVector = Vector::new(vec![Some(uri.cast()?), None]).into(); - assert_eq!(v.IndexOf(&uri.cast::()?, &mut index)?, true); + assert!(v.IndexOf(&uri.cast::()?, &mut index)?); assert_eq!(index, 0); - assert_eq!(v.IndexOf(None, &mut index)?, true); + assert!(v.IndexOf(None, &mut index)?); assert_eq!(index, 1); - assert_eq!( - v.IndexOf( + assert!( + !(v.IndexOf( &Uri::CreateUri(&HSTRING::from("http://test/"))?.cast::()?, &mut index - )?, - false + )?) ); Ok(()) @@ -248,11 +247,11 @@ fn test() -> Result<()> { ); // TODO: needs to have `1 let mut index = 0; - assert_eq!(true, v.IndexOf(20, &mut index)?); + assert!(v.IndexOf(20, &mut index)?); assert_eq!(1, index); - assert_eq!(true, v.IndexOf(30, &mut index)?); + assert!(v.IndexOf(30, &mut index)?); assert_eq!(2, index); - assert_eq!(false, v.IndexOf(123, &mut index)?); + assert!(!(v.IndexOf(123, &mut index)?)); let v: IVectorView = Vector::new(vec!["10".into(), "20".into(), "30".into()]).into(); assert_eq!("10", v.GetAt(0)?); @@ -261,11 +260,11 @@ fn test() -> Result<()> { assert_eq!(3, v.Size()?); let mut index = 0; - assert_eq!(true, v.IndexOf(&HSTRING::from("20"), &mut index)?); + assert!(v.IndexOf(&HSTRING::from("20"), &mut index)?); assert_eq!(1, index); - assert_eq!(true, v.IndexOf(&HSTRING::from("30"), &mut index)?); + assert!(v.IndexOf(&HSTRING::from("30"), &mut index)?); assert_eq!(2, index); - assert_eq!(false, v.IndexOf(&HSTRING::from("123"), &mut index)?); + assert!(!(v.IndexOf(&HSTRING::from("123"), &mut index)?)); let v: IVectorView = Vector::new(vec![ Some(Uri::CreateUri(&HSTRING::from("http://one/"))?.cast()?), diff --git a/crates/tests/misc/sys/tests/simple.rs b/crates/tests/misc/sys/tests/simple.rs index f7fd38c8d7..d075f77d8e 100644 --- a/crates/tests/misc/sys/tests/simple.rs +++ b/crates/tests/misc/sys/tests/simple.rs @@ -27,7 +27,7 @@ fn types() { // Handles let _: HANDLE = core::ptr::null_mut(); - let _: PSTR = b"hello\0".as_ptr() as _; + let _: PSTR = c"hello".as_ptr() as _; } #[test] diff --git a/crates/tests/misc/variant/tests/tests.rs b/crates/tests/misc/variant/tests/tests.rs index e799b2628e..d120962dde 100644 --- a/crates/tests/misc/variant/tests/tests.rs +++ b/crates/tests/misc/variant/tests/tests.rs @@ -19,9 +19,9 @@ fn test_variant() -> Result<()> { let v = VARIANT::from(true); assert!(!v.is_empty()); assert_eq!(v.vt(), VT_BOOL); - assert_eq!(bool::try_from(&v)?, true); + assert!(bool::try_from(&v)?); let v = VARIANT::from(false); - assert_eq!(bool::try_from(&v)?, false); + assert!(!(bool::try_from(&v)?)); assert_eq!(VARIANT::from(true), VARIANT::from(true)); assert_eq!(VARIANT::from(false), VARIANT::from(false)); assert_ne!(VARIANT::from(true), VARIANT::from(false)); @@ -145,9 +145,9 @@ fn test_propvariant() -> Result<()> { let v = PROPVARIANT::from(true); assert!(!v.is_empty()); assert_eq!(v.vt(), VT_BOOL); - assert_eq!(bool::try_from(&v)?, true); + assert!(bool::try_from(&v)?); let v = PROPVARIANT::from(false); - assert_eq!(bool::try_from(&v)?, false); + assert!(!(bool::try_from(&v)?)); assert_eq!(PROPVARIANT::from(true), PROPVARIANT::from(true)); assert_eq!(PROPVARIANT::from(false), PROPVARIANT::from(false)); assert_ne!(PROPVARIANT::from(true), PROPVARIANT::from(false)); diff --git a/crates/tests/misc/win32/tests/win32.rs b/crates/tests/misc/win32/tests/win32.rs index 4a27937c52..09377251e1 100644 --- a/crates/tests/misc/win32/tests/win32.rs +++ b/crates/tests/misc/win32/tests/win32.rs @@ -49,7 +49,7 @@ fn rect() { assert!(rect.right == 3); assert!(rect.bottom == 4); - let clone = rect.clone(); + let clone = rect; assert!( clone @@ -142,7 +142,7 @@ fn bool_as_error() { fn com() -> windows::core::Result<()> { unsafe { let stream = CreateStreamOnHGlobal(None, true)?; - let values = vec![1u8, 2u8, 3u8, 4u8]; + let values = [1u8, 2u8, 3u8, 4u8]; let mut copied = 0; stream @@ -237,7 +237,7 @@ fn callback() { assert!(BOOL(789) == a.unwrap()(HWND(123 as _), s!("hello a"), HANDLE(456 as _))); let a: PROPENUMPROCW = Some(callback_w); - assert!(BOOL(789) == a.unwrap()(HWND(123 as _), w!("hello w").into(), HANDLE(456 as _))); + assert!(BOOL(789) == a.unwrap()(HWND(123 as _), w!("hello w"), HANDLE(456 as _))); } } diff --git a/crates/tests/winrt/collections/tests/stock_map_view.rs b/crates/tests/winrt/collections/tests/stock_map_view.rs index d9f2512156..327410d7c1 100644 --- a/crates/tests/winrt/collections/tests/stock_map_view.rs +++ b/crates/tests/winrt/collections/tests/stock_map_view.rs @@ -8,7 +8,7 @@ fn primitive() -> Result<()> { let m = IMapView::::from(BTreeMap::from([])); assert_eq!(m.Lookup(0).unwrap_err().code(), E_BOUNDS); assert_eq!(m.Size()?, 0); - assert_eq!(m.HasKey(0)?, false); + assert!(!(m.HasKey(0)?)); let mut left = None; let mut right = None; m.Split(&mut left, &mut right)?; @@ -18,7 +18,7 @@ fn primitive() -> Result<()> { assert_eq!(m.Lookup(1i32)?, 10u64); assert_eq!(m.Lookup(2)?, 20); assert_eq!(m.Size()?, 2); - assert_eq!(m.HasKey(2)?, true); + assert!(m.HasKey(2)?); let able: IIterable> = m.cast()?; let m2: IMapView = able.cast()?; @@ -115,7 +115,7 @@ fn hstring() -> Result<()> { let m = IMapView::::from(BTreeMap::new()); assert_eq!(m.Lookup(h!("missing")).unwrap_err().code(), E_BOUNDS); assert_eq!(m.Size()?, 0); - assert_eq!(m.HasKey(h!("missing"))?, false); + assert!(!(m.HasKey(h!("missing"))?)); let m = BTreeMap::from([("one".into(), 1), ("two".into(), 2)]); assert!(m.contains_key(h!("one"))); @@ -124,8 +124,8 @@ fn hstring() -> Result<()> { assert_eq!(m.Lookup(h!("one"))?, 1); assert_eq!(m.Lookup(h!("two"))?, 2); assert_eq!(m.Size()?, 2); - assert_eq!(m.HasKey(h!("one"))?, true); - assert_eq!(m.HasKey(h!("three"))?, false); + assert!(m.HasKey(h!("one"))?); + assert!(!(m.HasKey(h!("three"))?)); let able: IIterable> = m.cast()?; let m2: IMapView = able.cast()?; diff --git a/crates/tests/winrt/collections/tests/stock_vector_view.rs b/crates/tests/winrt/collections/tests/stock_vector_view.rs index c325beca05..9d6e0c5d80 100644 --- a/crates/tests/winrt/collections/tests/stock_vector_view.rs +++ b/crates/tests/winrt/collections/tests/stock_vector_view.rs @@ -7,7 +7,7 @@ fn primitive() -> Result<()> { let v = IVectorView::::from(vec![]); assert_eq!(v.GetAt(0).unwrap_err().code(), E_BOUNDS); assert_eq!(v.Size()?, 0); - assert_eq!(v.IndexOf(0, &mut 0)?, false); + assert!(!(v.IndexOf(0, &mut 0)?)); assert_eq!(v.GetMany(0, &mut [0; 5])?, 0); let v = IVectorView::::from(vec![1, 2, 3]); @@ -16,12 +16,12 @@ fn primitive() -> Result<()> { assert_eq!(v.GetAt(2)?, 3); assert_eq!(v.Size()?, 3); let mut index = 0; - assert_eq!(v.IndexOf(0, &mut index)?, false); - assert_eq!(v.IndexOf(1, &mut index)?, true); + assert!(!(v.IndexOf(0, &mut index)?)); + assert!(v.IndexOf(1, &mut index)?); assert_eq!(index, 0); - assert_eq!(v.IndexOf(2, &mut index)?, true); + assert!(v.IndexOf(2, &mut index)?); assert_eq!(index, 1); - assert_eq!(v.IndexOf(3, &mut index)?, true); + assert!(v.IndexOf(3, &mut index)?); assert_eq!(index, 2); let mut values = [0; 5];