diff --git a/crates/libs/core/src/unknown.rs b/crates/libs/core/src/unknown.rs index 680f0baaf4..92bb3ad70b 100644 --- a/crates/libs/core/src/unknown.rs +++ b/crates/libs/core/src/unknown.rs @@ -117,16 +117,6 @@ pub trait IUnknownImpl { /// Gets the trust level of the current object. unsafe fn GetTrustLevel(&self, value: *mut i32) -> HRESULT; - /// Given a reference to an inner type, returns a reference to the outer shared type. - /// - /// # Safety - /// - /// This function should only be called from methods that implement COM interfaces, i.e. - /// implementations of methods on `IFoo_Impl` traits. - // TODO: This can be made safe, if IFoo_Impl are moved to the Object_Impl types. - // That requires some substantial redesign, though. - unsafe fn from_inner_ref(inner: &Self::Impl) -> &Self; - /// Gets a borrowed reference to an interface that is implemented by this ComObject. /// /// The returned reference does not have an additional reference count. @@ -158,10 +148,6 @@ pub trait IUnknownImpl { fn to_object(&self) -> ComObject where Self::Impl: ComObjectInner; - - /// The distance from the start of `_Impl` to the `this` field within it, measured in - /// pointer-sized elements. The `this` field contains the `MyApp` instance. - const INNER_OFFSET_IN_POINTERS: usize; } impl IUnknown_Vtbl { diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index b88edfe0e3..983d5c6ddd 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -117,11 +117,6 @@ pub fn implement( quote!() }; - // The distance from the beginning of the generated type to the 'this' field, in units of pointers (not bytes). - let offset_of_this_in_pointers = 1 + attributes.implement.len(); - let offset_of_this_in_pointers_token = - proc_macro2::Literal::usize_unsuffixed(offset_of_this_in_pointers); - let trust_level = proc_macro2::Literal::usize_unsuffixed(attributes.trust_level); let conversions = attributes.implement.iter().enumerate().map(|(enumerate, implement)| { @@ -309,11 +304,6 @@ pub fn implement( ::windows_core::HRESULT(0) } - unsafe fn from_inner_ref(inner: &Self::Impl) -> &Self { - &*((inner as *const Self::Impl as *const *const ::core::ffi::c_void) - .sub(#offset_of_this_in_pointers_token) as *const Self) - } - fn to_object(&self) -> ::windows_core::ComObject { self.count.add_ref(); unsafe { @@ -322,8 +312,6 @@ pub fn implement( ) } } - - const INNER_OFFSET_IN_POINTERS: usize = #offset_of_this_in_pointers_token; } impl #generics ::core::convert::From<#original_ident::#generics> for ::windows_core::IUnknown where #constraints { diff --git a/crates/tests/libs/implement_core/src/com_object.rs b/crates/tests/libs/implement_core/src/com_object.rs index a34852067f..ca8168e424 100644 --- a/crates/tests/libs/implement_core/src/com_object.rs +++ b/crates/tests/libs/implement_core/src/com_object.rs @@ -47,8 +47,7 @@ impl IFoo_Impl for MyApp_Impl { } unsafe fn get_self_as_bar(&self) -> IBar { - let outer = MyApp_Impl::from_inner_ref(self); - outer.to_interface() + self.to_interface() } unsafe fn common(&self) -> u32 {