Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Rust nightly compiler warnings #3311

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/tokens/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ 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) {
<T as RepAsIteratorExt>::quote_into_iter(*self)
}
}

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) {
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/tokens/to_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ pub trait ToTokens {
}
}

impl<'a, T: ?Sized + ToTokens> ToTokens for &'a T {
impl<T: ?Sized + ToTokens> 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<T: ?Sized + ToTokens> 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<T: ?Sized + ToOwned + ToTokens> ToTokens for Cow<'_, T> {
fn to_tokens(&self, tokens: &mut TokenStream) {
(**self).to_tokens(tokens);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/libs/core/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,21 @@ pub unsafe fn from_raw_borrowed<T: Interface>(raw: &*mut c_void) -> Option<&T> {
#[repr(transparent)]
pub struct InterfaceRef<'a, I>(NonNull<c_void>, PhantomData<&'a I>);

impl<'a, I> Copy for InterfaceRef<'a, I> {}
impl<I> Copy for InterfaceRef<'_, I> {}

impl<'a, I> Clone for InterfaceRef<'a, I> {
impl<I> Clone for InterfaceRef<'_, I> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, I: core::fmt::Debug + Interface> core::fmt::Debug for InterfaceRef<'a, I> {
impl<I: core::fmt::Debug + Interface> core::fmt::Debug for InterfaceRef<'_, I> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
<I as core::fmt::Debug>::fmt(&**self, f)
}
}

impl<'a, I: Interface> InterfaceRef<'a, I> {
impl<I: Interface> InterfaceRef<'_, I> {
/// Creates an `InterfaceRef` from a raw pointer. _This is extremely dangerous, since there
/// is no lifetime tracking at all!_
///
Expand Down Expand Up @@ -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<I: Interface> core::ops::Deref for InterfaceRef<'_, I> {
type Target = I;

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/src/out_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::*;
#[repr(transparent)]
pub struct OutRef<'a, T: Type<T>>(*mut T::Abi, core::marker::PhantomData<&'a T>);

impl<'a, T: Type<T>> OutRef<'a, T> {
impl<T: Type<T>> OutRef<'_, T> {
/// Returns `true` if the argument is null.
pub fn is_null(&self) -> bool {
self.0.is_null()
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::mem::transmute;
#[repr(transparent)]
pub struct Ref<'a, T: Type<T>>(T::Abi, PhantomData<&'a T>);

impl<'a, T: Type<T, Default = Option<T>, Abi = *mut c_void>> Ref<'a, T> {
impl<T: Type<T, Default = Option<T>, 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() {
Expand All @@ -18,7 +18,7 @@ impl<'a, T: Type<T, Default = Option<T>, Abi = *mut c_void>> Ref<'a, T> {
}
}

impl<'a, T: Type<T>> core::ops::Deref for Ref<'a, T> {
impl<T: Type<T>> core::ops::Deref for Ref<'_, T> {
type Target = T::Default;
fn deref(&self) -> &Self::Target {
unsafe { transmute(&self.0) }
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/core/src/scoped_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ScopedInterface<'a, T: Interface> {
lifetime: PhantomData<&'a T>,
}

impl<'a, T: Interface> ScopedInterface<'a, T> {
impl<T: Interface> ScopedInterface<'_, T> {
pub fn new(interface: T) -> Self {
Self {
interface,
Expand All @@ -24,15 +24,15 @@ impl<'a, T: Interface> ScopedInterface<'a, T> {
}
}

impl<'a, T: Interface> core::ops::Deref for ScopedInterface<'a, T> {
impl<T: Interface> core::ops::Deref for ScopedInterface<'_, T> {
type Target = T;

fn deref(&self) -> &T {
&self.interface
}
}

impl<'a, T: Interface> Drop for ScopedInterface<'a, T> {
impl<T: Interface> Drop for ScopedInterface<'_, T> {
fn drop(&mut self) {
unsafe {
let _ = Box::from_raw(self.interface.as_raw() as *const _ as *mut ScopedHeap);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/registry/src/key_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/registry/src/value_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/strings/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/strings/src/hstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
Expand All @@ -374,7 +374,7 @@ impl TryFrom<HSTRING> 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()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/misc/array/tests/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>();
assert_eq!(result, 6);

let a = Array::<i32>::from_slice(&[4, 5, 6]);
Expand Down
3 changes: 1 addition & 2 deletions crates/tests/misc/bcrypt/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/tests/misc/bcrypt/tests/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/misc/calling_convention/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/misc/class_hierarchy/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ fn call_interface(b: &IMemoryBuffer) -> Result<()> {
}

fn as_class<P: Param<MemoryBuffer>>(b: P) -> Result<()> {
unsafe { call_class(&b.param().borrow().as_ref().unwrap()) }
unsafe { call_class(b.param().borrow().as_ref().unwrap()) }
}

fn as_interface<P: Param<IMemoryBuffer>>(b: P) -> Result<()> {
unsafe { call_interface(&b.param().borrow().as_ref().unwrap()) }
unsafe { call_interface(b.param().borrow().as_ref().unwrap()) }
}
24 changes: 12 additions & 12 deletions crates/tests/misc/error/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand All @@ -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)");
Expand All @@ -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)");
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/misc/extensions/tests/bool32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/misc/extensions/tests/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions crates/tests/misc/extensions/tests/ntstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -64,9 +64,9 @@ fn is_valid(status: NTSTATUS) -> Result<bool> {

#[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(())
}
8 changes: 4 additions & 4 deletions crates/tests/misc/extensions/tests/variant_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions crates/tests/misc/handles/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -24,15 +24,15 @@ 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());
}

#[test]
fn pwstr() {
let handle = PWSTR::null();
let _clone = handle.clone();
let _clone = handle;
let _copy: PWSTR = handle;
assert!(handle.is_null());
}
Expand Down
Loading