diff --git a/crates/libs/core/src/imp/mod.rs b/crates/libs/core/src/imp/mod.rs index be219aee6ae..31c7850dcb4 100644 --- a/crates/libs/core/src/imp/mod.rs +++ b/crates/libs/core/src/imp/mod.rs @@ -77,22 +77,32 @@ pub use required_hierarchy; macro_rules! define_interface { ($name:ident, $vtbl:ident, $iid:literal) => { #[repr(transparent)] - #[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug, ::core::clone::Clone)] + #[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::clone::Clone)] pub struct $name(::windows_core::IUnknown); unsafe impl ::windows_core::Interface for $name { type Vtable = $vtbl; const IID: ::windows_core::GUID = ::windows_core::GUID::from_u128($iid); } + impl ::core::fmt::Debug for $name { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple(stringify!($name)).field(&::windows_core::Interface::as_raw(self)).finish() + } + } }; ($name:ident, $vtbl:ident) => { #[repr(transparent)] - #[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug, ::core::clone::Clone)] + #[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::clone::Clone)] pub struct $name(::std::ptr::NonNull<::std::ffi::c_void>); unsafe impl ::windows_core::Interface for $name { type Vtable = $vtbl; const IID: ::windows_core::GUID = ::windows_core::GUID::zeroed(); const UNKNOWN: bool = false; } + impl ::core::fmt::Debug for $name { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple(stringify!($name)).field(&self.0).finish() + } + } }; } diff --git a/crates/libs/core/src/unknown.rs b/crates/libs/core/src/unknown.rs index 86a08bb9206..97cc4c90474 100644 --- a/crates/libs/core/src/unknown.rs +++ b/crates/libs/core/src/unknown.rs @@ -55,7 +55,7 @@ impl Eq for IUnknown {} impl core::fmt::Debug for IUnknown { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("IUnknown").field(&self.0).finish() + f.debug_tuple("IUnknown").field(&self.as_raw()).finish() } } diff --git a/crates/libs/interface/src/lib.rs b/crates/libs/interface/src/lib.rs index 908e38a1377..1387b6f3d15 100644 --- a/crates/libs/interface/src/lib.rs +++ b/crates/libs/interface/src/lib.rs @@ -361,7 +361,7 @@ impl Interface { impl ::core::cmp::Eq for #name {} impl ::core::fmt::Debug for #name { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_tuple(#name_string).field(&self.0).finish() + f.debug_tuple(#name_string).field(&::windows_core::Interface::as_raw(self)).finish() } } } diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index 0afa0f6b383..249fc397fef 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -20,6 +20,6 @@ fn agile_debug() -> Result<()> { assert!(format!("{uri:?}").starts_with("Uri(IUnknown(0x")); let reference = AgileReference::new(&uri)?; - assert!(format!("{reference:?}").starts_with("AgileReference(IAgileReference(IUnknown(0x")); + assert!(format!("{reference:?}").starts_with("AgileReference(IAgileReference(0x")); Ok(()) } diff --git a/crates/tests/implement_core/src/com_object.rs b/crates/tests/implement_core/src/com_object.rs index 6959bdcb7b9..6cf227be893 100644 --- a/crates/tests/implement_core/src/com_object.rs +++ b/crates/tests/implement_core/src/com_object.rs @@ -416,6 +416,15 @@ fn common_method_name() { assert_eq!(unsafe { ibar2.common() }, std::f32::consts::PI); } +#[test] +fn debug_fmt() { + let app = MyApp::new(42); + let iunknown: IUnknown = app.to_interface(); + println!("IUnknown = {iunknown:?}"); + let ifoo: IFoo = app.to_interface(); + println!("IFoo = {ifoo:?}"); +} + // This tests that we can place a type that is not Send in a ComObject. // Compilation is sufficient to test. #[implement(IBar)]