Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make Debug impl for unions opaque #4176

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
62 changes: 0 additions & 62 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,31 +3064,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("__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 {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
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
62 changes: 0 additions & 62 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 @@ -1721,13 +1719,6 @@ cfg_if! {
}
}
impl Eq for __c_anonymous_cr_pid {}
impl fmt::Debug for __c_anonymous_cr_pid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("cr_pid")
.field("cr_pid", unsafe { &self.cr_pid })
.finish()
}
}
impl hash::Hash for __c_anonymous_cr_pid {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe { self.cr_pid.hash(state) };
Expand Down Expand Up @@ -1883,13 +1874,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 +1911,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 +1960,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 +2068,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 +2083,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 @@ -250,13 +250,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
Loading