Skip to content

Commit 6faa521

Browse files
zzau13tgross35
authored andcommitted
fix: make Debug impl for unions opaque
1 parent 96ed9c6 commit 6faa521

File tree

25 files changed

+9
-439
lines changed

25 files changed

+9
-439
lines changed

src/macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ macro_rules! s_no_extra_traits {
159159
$(#[$attr])*
160160
pub union $i { $($field)* }
161161
}
162+
163+
#[cfg(feature = "extra_traits")]
164+
impl ::core::fmt::Debug for $i {
165+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
166+
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
167+
}
168+
}
162169
);
163170

164171
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (

src/unix/aix/mod.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,6 @@ cfg_if! {
575575
}
576576
}
577577
impl Eq for __sigaction_sa_union {}
578-
impl fmt::Debug for __sigaction_sa_union {
579-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
580-
f.debug_struct("__sigaction_sa_union")
581-
.field("__su_handler", unsafe { &self.__su_handler })
582-
.field("__su_sigaction", unsafe { &self.__su_sigaction })
583-
.finish()
584-
}
585-
}
586578
impl hash::Hash for __sigaction_sa_union {
587579
fn hash<H: hash::Hasher>(&self, state: &mut H) {
588580
unsafe {
@@ -627,15 +619,6 @@ cfg_if! {
627619
}
628620
}
629621
impl Eq for __poll_ctl_ext_u {}
630-
impl fmt::Debug for __poll_ctl_ext_u {
631-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
632-
f.debug_struct("__poll_ctl_ext_u")
633-
.field("addr", unsafe { &self.addr })
634-
.field("data32", unsafe { &self.data32 })
635-
.field("data", unsafe { &self.data })
636-
.finish()
637-
}
638-
}
639622
impl hash::Hash for __poll_ctl_ext_u {
640623
fn hash<H: hash::Hasher>(&self, state: &mut H) {
641624
unsafe {

src/unix/aix/powerpc64.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,6 @@ cfg_if! {
356356
}
357357
}
358358
impl Eq for _kernel_simple_lock {}
359-
impl fmt::Debug for _kernel_simple_lock {
360-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
361-
f.debug_struct("_kernel_simple_lock")
362-
.field("_slock", unsafe { &self._slock })
363-
.field("_slockp", unsafe { &self._slockp })
364-
.finish()
365-
}
366-
}
367359
impl hash::Hash for _kernel_simple_lock {
368360
fn hash<H: hash::Hasher>(&self, state: &mut H) {
369361
unsafe {
@@ -475,15 +467,6 @@ cfg_if! {
475467
}
476468
}
477469
impl Eq for __ld_info_file {}
478-
impl fmt::Debug for __ld_info_file {
479-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
480-
f.debug_struct("__ld_info_file")
481-
.field("_ldinfo_fd", unsafe { &self._ldinfo_fd })
482-
.field("_ldinfo_fp", unsafe { &self._ldinfo_fp })
483-
.field("_core_offset", unsafe { &self._core_offset })
484-
.finish()
485-
}
486-
}
487470
impl hash::Hash for __ld_info_file {
488471
fn hash<H: hash::Hasher>(&self, state: &mut H) {
489472
unsafe {
@@ -544,15 +527,6 @@ cfg_if! {
544527
}
545528
}
546529
impl Eq for __pollfd_ext_u {}
547-
impl fmt::Debug for __pollfd_ext_u {
548-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
549-
f.debug_struct("__pollfd_ext_u")
550-
.field("addr", unsafe { &self.addr })
551-
.field("data32", unsafe { &self.data32 })
552-
.field("data", unsafe { &self.data })
553-
.finish()
554-
}
555-
}
556530
impl hash::Hash for __pollfd_ext_u {
557531
fn hash<H: hash::Hasher>(&self, state: &mut H) {
558532
unsafe {

src/unix/bsd/apple/mod.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,13 +1680,6 @@ cfg_if! {
16801680
}
16811681
}
16821682
impl Eq for semun {}
1683-
impl fmt::Debug for semun {
1684-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1685-
f.debug_struct("semun")
1686-
.field("val", unsafe { &self.val })
1687-
.finish()
1688-
}
1689-
}
16901683
impl hash::Hash for semun {
16911684
fn hash<H: hash::Hasher>(&self, state: &mut H) {
16921685
unsafe { self.val.hash(state) };
@@ -3009,15 +3002,6 @@ cfg_if! {
30093002
}
30103003

30113004
impl Eq for __c_anonymous_ifk_data {}
3012-
3013-
impl fmt::Debug for __c_anonymous_ifk_data {
3014-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3015-
f.debug_struct("__c_anonymous_ifk_data")
3016-
.field("ifk_ptr", unsafe { &self.ifk_ptr })
3017-
.field("ifk_value", unsafe { &self.ifk_value })
3018-
.finish()
3019-
}
3020-
}
30213005
impl hash::Hash for __c_anonymous_ifk_data {
30223006
fn hash<H: hash::Hasher>(&self, state: &mut H) {
30233007
unsafe {
@@ -3080,31 +3064,6 @@ cfg_if! {
30803064

30813065
impl Eq for __c_anonymous_ifr_ifru {}
30823066

3083-
impl fmt::Debug for __c_anonymous_ifr_ifru {
3084-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3085-
f.debug_struct("__c_anonymous_ifr_ifru")
3086-
.field("ifru_addr", unsafe { &self.ifru_addr })
3087-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
3088-
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
3089-
.field("ifru_flags", unsafe { &self.ifru_flags })
3090-
.field("ifru_metrics", unsafe { &self.ifru_metrics })
3091-
.field("ifru_mtu", unsafe { &self.ifru_mtu })
3092-
.field("ifru_phys", unsafe { &self.ifru_phys })
3093-
.field("ifru_media", unsafe { &self.ifru_media })
3094-
.field("ifru_intval", unsafe { &self.ifru_intval })
3095-
.field("ifru_data", unsafe { &self.ifru_data })
3096-
.field("ifru_devmtu", unsafe { &self.ifru_devmtu })
3097-
.field("ifru_kpi", unsafe { &self.ifru_kpi })
3098-
.field("ifru_wake_flags", unsafe { &self.ifru_wake_flags })
3099-
.field("ifru_route_refcnt", unsafe { &self.ifru_route_refcnt })
3100-
.field("ifru_cap", unsafe { &self.ifru_cap })
3101-
.field("ifru_functional_type", unsafe {
3102-
&self.ifru_functional_type
3103-
})
3104-
.finish()
3105-
}
3106-
}
3107-
31083067
impl hash::Hash for __c_anonymous_ifr_ifru {
31093068
fn hash<H: hash::Hasher>(&self, state: &mut H) {
31103069
unsafe {
@@ -3158,12 +3117,6 @@ cfg_if! {
31583117
}
31593118
}
31603119

3161-
impl fmt::Debug for __c_anonymous_ifc_ifcu {
3162-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3163-
f.debug_struct("ifc_ifcu").finish_non_exhaustive()
3164-
}
3165-
}
3166-
31673120
impl PartialEq for __c_anonymous_ifr_ifru6 {
31683121
fn eq(&self, other: &__c_anonymous_ifr_ifru6) -> bool {
31693122
unsafe {
@@ -3185,21 +3138,6 @@ cfg_if! {
31853138

31863139
impl Eq for __c_anonymous_ifr_ifru6 {}
31873140

3188-
impl fmt::Debug for __c_anonymous_ifr_ifru6 {
3189-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3190-
f.debug_struct("__c_anonymous_ifr_ifru6")
3191-
.field("ifru_addr", unsafe { &self.ifru_addr })
3192-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
3193-
.field("ifru_flags", unsafe { &self.ifru_flags })
3194-
.field("ifru_flags6", unsafe { &self.ifru_flags6 })
3195-
.field("ifru_metrics", unsafe { &self.ifru_metrics })
3196-
.field("ifru_intval", unsafe { &self.ifru_intval })
3197-
.field("ifru_data", unsafe { &self.ifru_data })
3198-
.field("ifru_scope_id", unsafe { &self.ifru_scope_id })
3199-
.finish()
3200-
}
3201-
}
3202-
32033141
impl hash::Hash for __c_anonymous_ifr_ifru6 {
32043142
fn hash<H: hash::Hasher>(&self, state: &mut H) {
32053143
unsafe {

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,6 @@ s_no_extra_traits! {
13651365
pub aio_sigevent: sigevent,
13661366
}
13671367

1368-
// Can't correctly impl Debug for unions
1369-
#[allow(missing_debug_implementations)]
13701368
pub union __c_anonymous_sigev_un {
13711369
pub _threadid: crate::__lwpid_t,
13721370
pub _sigev_thread: __c_anonymous_sigev_thread,
@@ -1721,13 +1719,6 @@ cfg_if! {
17211719
}
17221720
}
17231721
impl Eq for __c_anonymous_cr_pid {}
1724-
impl fmt::Debug for __c_anonymous_cr_pid {
1725-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1726-
f.debug_struct("cr_pid")
1727-
.field("cr_pid", unsafe { &self.cr_pid })
1728-
.finish()
1729-
}
1730-
}
17311722
impl hash::Hash for __c_anonymous_cr_pid {
17321723
fn hash<H: hash::Hasher>(&self, state: &mut H) {
17331724
unsafe { self.cr_pid.hash(state) };
@@ -1883,13 +1874,6 @@ cfg_if! {
18831874
}
18841875
}
18851876
impl Eq for __c_anonymous_elf32_auxv_union {}
1886-
impl fmt::Debug for __c_anonymous_elf32_auxv_union {
1887-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1888-
f.debug_struct("a_val")
1889-
.field("a_val", unsafe { &self.a_val })
1890-
.finish()
1891-
}
1892-
}
18931877
impl PartialEq for Elf32_Auxinfo {
18941878
fn eq(&self, other: &Elf32_Auxinfo) -> bool {
18951879
self.a_type == other.a_type && self.a_un == other.a_un
@@ -1927,27 +1911,6 @@ cfg_if! {
19271911
}
19281912
}
19291913
impl Eq for __c_anonymous_ifr_ifru {}
1930-
impl fmt::Debug for __c_anonymous_ifr_ifru {
1931-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1932-
f.debug_struct("ifr_ifru")
1933-
.field("ifru_addr", unsafe { &self.ifru_addr })
1934-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
1935-
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
1936-
.field("ifru_buffer", unsafe { &self.ifru_buffer })
1937-
.field("ifru_flags", unsafe { &self.ifru_flags })
1938-
.field("ifru_index", unsafe { &self.ifru_index })
1939-
.field("ifru_jid", unsafe { &self.ifru_jid })
1940-
.field("ifru_metric", unsafe { &self.ifru_metric })
1941-
.field("ifru_mtu", unsafe { &self.ifru_mtu })
1942-
.field("ifru_phys", unsafe { &self.ifru_phys })
1943-
.field("ifru_media", unsafe { &self.ifru_media })
1944-
.field("ifru_data", unsafe { &self.ifru_data })
1945-
.field("ifru_cap", unsafe { &self.ifru_cap })
1946-
.field("ifru_fib", unsafe { &self.ifru_fib })
1947-
.field("ifru_vlan_pcp", unsafe { &self.ifru_vlan_pcp })
1948-
.finish()
1949-
}
1950-
}
19511914
impl hash::Hash for __c_anonymous_ifr_ifru {
19521915
fn hash<H: hash::Hasher>(&self, state: &mut H) {
19531916
unsafe { self.ifru_addr.hash(state) };
@@ -1997,15 +1960,6 @@ cfg_if! {
19971960
}
19981961
}
19991962

2000-
impl fmt::Debug for __c_anonymous_ifc_ifcu {
2001-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2002-
f.debug_struct("ifc_ifcu")
2003-
.field("ifcu_buf", unsafe { &self.ifcu_buf })
2004-
.field("ifcu_req", unsafe { &self.ifcu_req })
2005-
.finish()
2006-
}
2007-
}
2008-
20091963
impl hash::Hash for __c_anonymous_ifc_ifcu {
20101964
fn hash<H: hash::Hasher>(&self, state: &mut H) {
20111965
unsafe { self.ifcu_buf.hash(state) };
@@ -2114,14 +2068,6 @@ cfg_if! {
21142068
}
21152069
}
21162070
impl Eq for __c_anonymous_ifi_epoch {}
2117-
impl fmt::Debug for __c_anonymous_ifi_epoch {
2118-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2119-
f.debug_struct("__c_anonymous_ifi_epoch")
2120-
.field("tt", unsafe { &self.tt })
2121-
.field("ph", unsafe { &self.ph })
2122-
.finish()
2123-
}
2124-
}
21252071
impl hash::Hash for __c_anonymous_ifi_epoch {
21262072
fn hash<H: hash::Hasher>(&self, state: &mut H) {
21272073
unsafe {
@@ -2137,14 +2083,6 @@ cfg_if! {
21372083
}
21382084
}
21392085
impl Eq for __c_anonymous_ifi_lastchange {}
2140-
impl fmt::Debug for __c_anonymous_ifi_lastchange {
2141-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2142-
f.debug_struct("__c_anonymous_ifi_lastchange")
2143-
.field("tv", unsafe { &self.tv })
2144-
.field("ph", unsafe { &self.ph })
2145-
.finish()
2146-
}
2147-
}
21482086
impl hash::Hash for __c_anonymous_ifi_lastchange {
21492087
fn hash<H: hash::Hasher>(&self, state: &mut H) {
21502088
unsafe {

src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,6 @@ cfg_if! {
250250
}
251251
}
252252
impl Eq for __c_anonymous_elf64_auxv_union {}
253-
impl fmt::Debug for __c_anonymous_elf64_auxv_union {
254-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
255-
f.debug_struct("a_val")
256-
.field("a_val", unsafe { &self.a_val })
257-
.finish()
258-
}
259-
}
260253
impl PartialEq for Elf64_Auxinfo {
261254
fn eq(&self, other: &Elf64_Auxinfo) -> bool {
262255
self.a_type == other.a_type && self.a_un == other.a_un

src/unix/bsd/netbsdlike/netbsd/aarch64.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@ cfg_if! {
5454
}
5555
}
5656
impl Eq for __c_anonymous__freg {}
57-
impl fmt::Debug for __c_anonymous__freg {
58-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59-
unsafe {
60-
f.debug_struct("__c_anonymous__freg")
61-
.field("__b8", &self.__b8)
62-
.field("__h16", &self.__h16)
63-
.field("__s32", &self.__s32)
64-
.field("__d64", &self.__d64)
65-
.field("__q128", &self.__q128)
66-
.finish()
67-
}
68-
}
69-
}
7057
impl hash::Hash for __c_anonymous__freg {
7158
fn hash<H: hash::Hasher>(&self, state: &mut H) {
7259
unsafe {

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,17 +1340,6 @@ cfg_if! {
13401340
}
13411341
}
13421342

1343-
impl fmt::Debug for __c_anonymous_posix_spawn_fae {
1344-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1345-
unsafe {
1346-
f.debug_struct("__c_anonymous_posix_fae")
1347-
.field("open", &self.open)
1348-
.field("dup2", &self.dup2)
1349-
.finish()
1350-
}
1351-
}
1352-
}
1353-
13541343
impl hash::Hash for __c_anonymous_posix_spawn_fae {
13551344
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13561345
unsafe {
@@ -1368,17 +1357,6 @@ cfg_if! {
13681357
}
13691358
}
13701359

1371-
impl fmt::Debug for __c_anonymous_ifc_ifcu {
1372-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1373-
unsafe {
1374-
f.debug_struct("__c_anonymous_ifc_ifcu")
1375-
.field("ifcu_buf", &self.ifcu_buf)
1376-
.field("ifcu_req", &self.ifcu_req)
1377-
.finish()
1378-
}
1379-
}
1380-
}
1381-
13821360
impl hash::Hash for __c_anonymous_ifc_ifcu {
13831361
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13841362
unsafe {

src/unix/bsd/netbsdlike/netbsd/riscv64.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ s! {
1919
}
2020

2121
s_no_extra_traits! {
22-
#[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))]
2322
pub union __fpreg {
2423
pub u_u64: u64,
2524
pub u_d: c_double,

0 commit comments

Comments
 (0)