Skip to content

Commit

Permalink
fix: make Debug impl for unions opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
zzau13 committed Dec 7, 2024
1 parent 149d392 commit 459fbe6
Show file tree
Hide file tree
Showing 25 changed files with 17 additions and 426 deletions.
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ macro_rules! s_no_extra_traits {
$(#[$attr])*
pub union $i { $($field)* }
}

#[cfg(feature = "extra_traits")]
impl ::core::fmt::Debug for $i {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
}
}
);

(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
Expand Down
17 changes: 0 additions & 17 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,6 @@ cfg_if! {
}
}
impl Eq for __sigaction_sa_union {}
impl fmt::Debug for __sigaction_sa_union {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("__sigaction_sa_union")
.field("__su_handler", unsafe { &self.__su_handler })
.field("__su_sigaction", unsafe { &self.__su_sigaction })
.finish()
}
}
impl hash::Hash for __sigaction_sa_union {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down Expand Up @@ -627,15 +619,6 @@ cfg_if! {
}
}
impl Eq for __poll_ctl_ext_u {}
impl fmt::Debug for __poll_ctl_ext_u {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("__poll_ctl_ext_u")
.field("addr", unsafe { &self.addr })
.field("data32", unsafe { &self.data32 })
.field("data", unsafe { &self.data })
.finish()
}
}
impl hash::Hash for __poll_ctl_ext_u {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
26 changes: 0 additions & 26 deletions src/unix/aix/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,6 @@ cfg_if! {
}
}
impl Eq for _kernel_simple_lock {}
impl fmt::Debug for _kernel_simple_lock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("_kernel_simple_lock")
.field("_slock", unsafe { &self._slock })
.field("_slockp", unsafe { &self._slockp })
.finish()
}
}
impl hash::Hash for _kernel_simple_lock {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down Expand Up @@ -475,15 +467,6 @@ cfg_if! {
}
}
impl Eq for __ld_info_file {}
impl fmt::Debug for __ld_info_file {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("__ld_info_file")
.field("_ldinfo_fd", unsafe { &self._ldinfo_fd })
.field("_ldinfo_fp", unsafe { &self._ldinfo_fp })
.field("_core_offset", unsafe { &self._core_offset })
.finish()
}
}
impl hash::Hash for __ld_info_file {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down Expand Up @@ -544,15 +527,6 @@ cfg_if! {
}
}
impl Eq for __pollfd_ext_u {}
impl fmt::Debug for __pollfd_ext_u {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("__pollfd_ext_u")
.field("addr", unsafe { &self.addr })
.field("data32", unsafe { &self.data32 })
.field("data", unsafe { &self.data })
.finish()
}
}
impl hash::Hash for __pollfd_ext_u {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
64 changes: 1 addition & 63 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1680,13 +1680,6 @@ cfg_if! {
}
}
impl Eq for semun {}
impl fmt::Debug for semun {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("semun")
.field("val", unsafe { &self.val })
.finish()
}
}
impl hash::Hash for semun {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe { self.val.hash(state) };
Expand Down Expand Up @@ -3009,15 +3002,6 @@ cfg_if! {
}

impl Eq for __c_anonymous_ifk_data {}

impl fmt::Debug for __c_anonymous_ifk_data {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("__c_anonymous_ifk_data")
.field("ifk_ptr", unsafe { &self.ifk_ptr })
.field("ifk_value", unsafe { &self.ifk_value })
.finish()
}
}
impl hash::Hash for __c_anonymous_ifk_data {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down Expand Up @@ -3080,32 +3064,7 @@ cfg_if! {

impl Eq for __c_anonymous_ifr_ifru {}

impl fmt::Debug for __c_anonymous_ifr_ifru {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("__c_anonymous_ifr_ifru")
.field("ifru_addr", unsafe { &self.ifru_addr })
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
.field("ifru_flags", unsafe { &self.ifru_flags })
.field("ifru_metrics", unsafe { &self.ifru_metrics })
.field("ifru_mtu", unsafe { &self.ifru_mtu })
.field("ifru_phys", unsafe { &self.ifru_phys })
.field("ifru_media", unsafe { &self.ifru_media })
.field("ifru_intval", unsafe { &self.ifru_intval })
.field("ifru_data", unsafe { &self.ifru_data })
.field("ifru_devmtu", unsafe { &self.ifru_devmtu })
.field("ifru_kpi", unsafe { &self.ifru_kpi })
.field("ifru_wake_flags", unsafe { &self.ifru_wake_flags })
.field("ifru_route_refcnt", unsafe { &self.ifru_route_refcnt })
.field("ifru_cap", unsafe { &self.ifru_cap })
.field("ifru_functional_type", unsafe {
&self.ifru_functional_type
})
.finish()
}
}

impl hash::Hash for __c_anonymous_ifr_ifru {
impl hash::Hash for __c_anonymous_ifr_ifru {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
self.ifru_addr.hash(state);
Expand Down Expand Up @@ -3158,12 +3117,6 @@ cfg_if! {
}
}

impl fmt::Debug for __c_anonymous_ifc_ifcu {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ifc_ifcu").finish_non_exhaustive()
}
}

impl PartialEq for __c_anonymous_ifr_ifru6 {
fn eq(&self, other: &__c_anonymous_ifr_ifru6) -> bool {
unsafe {
Expand All @@ -3185,21 +3138,6 @@ cfg_if! {

impl Eq for __c_anonymous_ifr_ifru6 {}

impl fmt::Debug for __c_anonymous_ifr_ifru6 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("__c_anonymous_ifr_ifru6")
.field("ifru_addr", unsafe { &self.ifru_addr })
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
.field("ifru_flags", unsafe { &self.ifru_flags })
.field("ifru_flags6", unsafe { &self.ifru_flags6 })
.field("ifru_metrics", unsafe { &self.ifru_metrics })
.field("ifru_intval", unsafe { &self.ifru_intval })
.field("ifru_data", unsafe { &self.ifru_data })
.field("ifru_scope_id", unsafe { &self.ifru_scope_id })
.finish()
}
}

impl hash::Hash for __c_anonymous_ifr_ifru6 {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
55 changes: 0 additions & 55 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,6 @@ s_no_extra_traits! {
pub aio_sigevent: sigevent,
}

// Can't correctly impl Debug for unions
#[allow(missing_debug_implementations)]
pub union __c_anonymous_sigev_un {
pub _threadid: crate::__lwpid_t,
pub _sigev_thread: __c_anonymous_sigev_thread,
Expand Down Expand Up @@ -1883,13 +1881,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_elf32_auxv_union {}
impl fmt::Debug for __c_anonymous_elf32_auxv_union {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("a_val")
.field("a_val", unsafe { &self.a_val })
.finish()
}
}
impl PartialEq for Elf32_Auxinfo {
fn eq(&self, other: &Elf32_Auxinfo) -> bool {
self.a_type == other.a_type && self.a_un == other.a_un
Expand Down Expand Up @@ -1927,27 +1918,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_ifr_ifru {}
impl fmt::Debug for __c_anonymous_ifr_ifru {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ifr_ifru")
.field("ifru_addr", unsafe { &self.ifru_addr })
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
.field("ifru_buffer", unsafe { &self.ifru_buffer })
.field("ifru_flags", unsafe { &self.ifru_flags })
.field("ifru_index", unsafe { &self.ifru_index })
.field("ifru_jid", unsafe { &self.ifru_jid })
.field("ifru_metric", unsafe { &self.ifru_metric })
.field("ifru_mtu", unsafe { &self.ifru_mtu })
.field("ifru_phys", unsafe { &self.ifru_phys })
.field("ifru_media", unsafe { &self.ifru_media })
.field("ifru_data", unsafe { &self.ifru_data })
.field("ifru_cap", unsafe { &self.ifru_cap })
.field("ifru_fib", unsafe { &self.ifru_fib })
.field("ifru_vlan_pcp", unsafe { &self.ifru_vlan_pcp })
.finish()
}
}
impl hash::Hash for __c_anonymous_ifr_ifru {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe { self.ifru_addr.hash(state) };
Expand Down Expand Up @@ -1997,15 +1967,6 @@ cfg_if! {
}
}

impl fmt::Debug for __c_anonymous_ifc_ifcu {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ifc_ifcu")
.field("ifcu_buf", unsafe { &self.ifcu_buf })
.field("ifcu_req", unsafe { &self.ifcu_req })
.finish()
}
}

impl hash::Hash for __c_anonymous_ifc_ifcu {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe { self.ifcu_buf.hash(state) };
Expand Down Expand Up @@ -2114,14 +2075,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_ifi_epoch {}
impl fmt::Debug for __c_anonymous_ifi_epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("__c_anonymous_ifi_epoch")
.field("tt", unsafe { &self.tt })
.field("ph", unsafe { &self.ph })
.finish()
}
}
impl hash::Hash for __c_anonymous_ifi_epoch {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand All @@ -2137,14 +2090,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_ifi_lastchange {}
impl fmt::Debug for __c_anonymous_ifi_lastchange {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("__c_anonymous_ifi_lastchange")
.field("tv", unsafe { &self.tv })
.field("ph", unsafe { &self.ph })
.finish()
}
}
impl hash::Hash for __c_anonymous_ifi_lastchange {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
7 changes: 0 additions & 7 deletions src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_elf64_auxv_union {}
impl fmt::Debug for __c_anonymous_elf64_auxv_union {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("a_val")
.field("a_val", unsafe { &self.a_val })
.finish()
}
}
impl PartialEq for Elf64_Auxinfo {
fn eq(&self, other: &Elf64_Auxinfo) -> bool {
self.a_type == other.a_type && self.a_un == other.a_un
Expand Down
13 changes: 0 additions & 13 deletions src/unix/bsd/netbsdlike/netbsd/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous__freg {}
impl fmt::Debug for __c_anonymous__freg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
f.debug_struct("__c_anonymous__freg")
.field("__b8", &self.__b8)
.field("__h16", &self.__h16)
.field("__s32", &self.__s32)
.field("__d64", &self.__d64)
.field("__q128", &self.__q128)
.finish()
}
}
}
impl hash::Hash for __c_anonymous__freg {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
22 changes: 0 additions & 22 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,17 +1340,6 @@ cfg_if! {
}
}

impl fmt::Debug for __c_anonymous_posix_spawn_fae {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
f.debug_struct("__c_anonymous_posix_fae")
.field("open", &self.open)
.field("dup2", &self.dup2)
.finish()
}
}
}

impl hash::Hash for __c_anonymous_posix_spawn_fae {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand All @@ -1368,17 +1357,6 @@ cfg_if! {
}
}

impl fmt::Debug for __c_anonymous_ifc_ifcu {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
f.debug_struct("__c_anonymous_ifc_ifcu")
.field("ifcu_buf", &self.ifcu_buf)
.field("ifcu_req", &self.ifcu_req)
.finish()
}
}
}

impl hash::Hash for __c_anonymous_ifc_ifcu {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/netbsdlike/netbsd/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ s! {
}

s_no_extra_traits! {
#[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))]
pub union __fpreg {
pub u_u64: u64,
pub u_d: c_double,
Expand Down
Loading

0 comments on commit 459fbe6

Please sign in to comment.