Skip to content

Commit

Permalink
Fix for new Clippy warnings in nightly (#2977)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Apr 8, 2024
1 parent ac4643e commit e7a361a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 11 deletions.
6 changes: 5 additions & 1 deletion crates/libs/core/src/agile_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ pub struct AgileReference<T>(imp::IAgileReference, PhantomData<T>);
impl<T: Interface> AgileReference<T> {
/// Creates an agile reference to the object.
pub fn new(object: &T) -> Result<Self> {
unsafe { imp::RoGetAgileReference(imp::AGILEREFERENCE_DEFAULT, &T::IID, std::mem::transmute::<_, &IUnknown>(object)).map(|reference| Self(reference, Default::default())) }
// TODO: this assert is required until we can catch this at compile time using an "associated const equality" constraint.
// For example, <T: Interface<UNKNOWN = true>>
// https://github.com/rust-lang/rust/issues/92827
assert!(T::UNKNOWN);
unsafe { imp::RoGetAgileReference(imp::AGILEREFERENCE_DEFAULT, &T::IID, std::mem::transmute::<&T, &IUnknown>(object)).map(|reference| Self(reference, Default::default())) }
}

/// Retrieves a proxy to the target of the `AgileReference` object that may safely be used within any thread context in which get is called.
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T: Type<T>> Array<T> {

/// Creates an array of the given length with default values.
pub fn with_len(len: usize) -> Self {
assert!(len < std::u32::MAX as usize);
assert!(len < u32::MAX as usize);
let bytes_amount = len.checked_mul(std::mem::size_of::<T>()).expect("Attempted to allocate too large an Array");

// WinRT arrays must be allocated with CoTaskMemAlloc.
Expand Down
7 changes: 4 additions & 3 deletions crates/libs/core/src/imp/factory_cache.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::*;
use crate::Interface;
use std::ffi::c_void;
use std::marker::PhantomData;
use std::sync::atomic::{AtomicPtr, Ordering};

#[doc(hidden)]
pub struct FactoryCache<C, I> {
shared: AtomicPtr<std::ffi::c_void>,
shared: AtomicPtr<c_void>,
_c: PhantomData<C>,
_i: PhantomData<I>,
}
Expand All @@ -30,7 +31,7 @@ impl<C: crate::RuntimeName, I: Interface> FactoryCache<C, I> {

// If a pointer is found, the cache is primed and we're good to go.
if !ptr.is_null() {
return callback(unsafe { std::mem::transmute(&ptr) });
return callback(unsafe { std::mem::transmute::<&*mut c_void, &I>(&ptr) });
}

// Otherwise, we load the factory the usual way.
Expand Down Expand Up @@ -125,7 +126,7 @@ unsafe fn get_activation_factory(library: crate::PCSTR, name: &crate::HSTRING) -
function(std::mem::transmute_copy(name), &mut abi).and_then(|| crate::Type::from_abi(abi))
}

type DllGetActivationFactory = extern "system" fn(name: *mut std::ffi::c_void, factory: *mut *mut std::ffi::c_void) -> crate::HRESULT;
type DllGetActivationFactory = extern "system" fn(name: *mut c_void, factory: *mut *mut c_void) -> crate::HRESULT;

#[cfg(test)]
mod tests {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/inspectable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl IInspectable {
unsafe {
let mut abi = std::ptr::null_mut();
(self.vtable().GetRuntimeClassName)(std::mem::transmute_copy(self), &mut abi).ok()?;
Ok(std::mem::transmute(abi))
Ok(std::mem::transmute::<*mut std::ffi::c_void, HSTRING>(abi))
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ impl IInspectable_Vtbl {
}
unsafe extern "system" fn GetRuntimeClassName<T: RuntimeName>(_: *mut std::ffi::c_void, value: *mut *mut std::ffi::c_void) -> HRESULT {
let h: HSTRING = T::NAME.into(); // TODO: should be try_into
*value = std::mem::transmute(h);
*value = std::mem::transmute::<HSTRING, *mut std::ffi::c_void>(h);
HRESULT(0)
}
unsafe extern "system" fn GetTrustLevel<T: IUnknownImpl, const OFFSET: isize>(this: *mut std::ffi::c_void, value: *mut i32) -> HRESULT {
Expand Down
2 changes: 1 addition & 1 deletion crates/samples/components/json_validator_winrt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extern "system" fn DllGetActivationFactory(
// `IActivationFactory` pointer and that's what `factory` contains.
unsafe {
if let Some(factory) = factory {
*result = std::mem::transmute(factory);
*result = factory.into_raw();
S_OK
} else {
*result = std::ptr::null_mut();
Expand Down
4 changes: 3 additions & 1 deletion crates/samples/windows/credentials/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ fn main() -> windows::core::Result<()> {
println!();
}

CredFree(std::mem::transmute(credentials_ptr));
CredFree(std::mem::transmute::<*mut *mut _, *const _>(
credentials_ptr,
));
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/samples/windows/direct3d12/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ mod d3d12_hello_triangle {
],
},
DepthStencilState: D3D12_DEPTH_STENCIL_DESC::default(),
SampleMask: u32::max_value(),
SampleMask: u32::MAX,
PrimitiveTopologyType: D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE,
NumRenderTargets: 1,
SampleDesc: DXGI_SAMPLE_DESC {
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ unsafe extern "system" fn DllGetActivationFactory(
};

if let Some(factory) = factory {
*result = std::mem::transmute(factory);
*result = factory.into_raw();
S_OK
} else {
*result = std::ptr::null_mut();
Expand Down

0 comments on commit e7a361a

Please sign in to comment.