diff --git a/crates/libs/core/src/agile_reference.rs b/crates/libs/core/src/agile_reference.rs index eb68e78c95..ca227afb28 100644 --- a/crates/libs/core/src/agile_reference.rs +++ b/crates/libs/core/src/agile_reference.rs @@ -9,7 +9,11 @@ pub struct AgileReference(imp::IAgileReference, PhantomData); impl AgileReference { /// Creates an agile reference to the object. pub fn new(object: &T) -> Result { - 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, > + // 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. diff --git a/crates/libs/core/src/array.rs b/crates/libs/core/src/array.rs index 9f8052c70a..d3af681ed0 100644 --- a/crates/libs/core/src/array.rs +++ b/crates/libs/core/src/array.rs @@ -20,7 +20,7 @@ impl> Array { /// 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::()).expect("Attempted to allocate too large an Array"); // WinRT arrays must be allocated with CoTaskMemAlloc. diff --git a/crates/libs/core/src/imp/factory_cache.rs b/crates/libs/core/src/imp/factory_cache.rs index 62085a1b73..50ddb87f78 100644 --- a/crates/libs/core/src/imp/factory_cache.rs +++ b/crates/libs/core/src/imp/factory_cache.rs @@ -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 { - shared: AtomicPtr, + shared: AtomicPtr, _c: PhantomData, _i: PhantomData, } @@ -30,7 +31,7 @@ impl FactoryCache { // 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. @@ -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 { diff --git a/crates/libs/core/src/inspectable.rs b/crates/libs/core/src/inspectable.rs index 8d8821ee1c..a3904804e4 100644 --- a/crates/libs/core/src/inspectable.rs +++ b/crates/libs/core/src/inspectable.rs @@ -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)) } } @@ -62,7 +62,7 @@ impl IInspectable_Vtbl { } unsafe extern "system" fn GetRuntimeClassName(_: *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::(h); HRESULT(0) } unsafe extern "system" fn GetTrustLevel(this: *mut std::ffi::c_void, value: *mut i32) -> HRESULT { diff --git a/crates/samples/components/json_validator_winrt/src/lib.rs b/crates/samples/components/json_validator_winrt/src/lib.rs index 931d641afa..b816b0d478 100644 --- a/crates/samples/components/json_validator_winrt/src/lib.rs +++ b/crates/samples/components/json_validator_winrt/src/lib.rs @@ -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(); diff --git a/crates/samples/windows/credentials/src/main.rs b/crates/samples/windows/credentials/src/main.rs index 0e0bec77a3..9d38b8bbd1 100644 --- a/crates/samples/windows/credentials/src/main.rs +++ b/crates/samples/windows/credentials/src/main.rs @@ -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(()) diff --git a/crates/samples/windows/direct3d12/src/main.rs b/crates/samples/windows/direct3d12/src/main.rs index d4af18f63b..3e0b2d323e 100644 --- a/crates/samples/windows/direct3d12/src/main.rs +++ b/crates/samples/windows/direct3d12/src/main.rs @@ -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 { diff --git a/crates/tests/component/src/lib.rs b/crates/tests/component/src/lib.rs index 29da70293e..08785be5c7 100644 --- a/crates/tests/component/src/lib.rs +++ b/crates/tests/component/src/lib.rs @@ -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();