Skip to content

Commit 7457aa1

Browse files
zzau13tgross35
authored andcommitted
fix: make Debug impl for unions opaque
(backport <#4176>) (cherry picked from commit 6faa521) [ resolve conflicts and update based on some main vs. 0.2 differences - Trevor ]
1 parent 8592ff9 commit 7457aa1

File tree

24 files changed

+7
-437
lines changed

24 files changed

+7
-437
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 & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,13 +1718,6 @@ cfg_if! {
17181718
}
17191719
}
17201720
impl Eq for semun {}
1721-
impl fmt::Debug for semun {
1722-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1723-
f.debug_struct("semun")
1724-
.field("val", unsafe { &self.val })
1725-
.finish()
1726-
}
1727-
}
17281721
impl hash::Hash for semun {
17291722
fn hash<H: hash::Hasher>(&self, state: &mut H) {
17301723
unsafe { self.val.hash(state) };
@@ -3073,15 +3066,6 @@ cfg_if! {
30733066
}
30743067

30753068
impl Eq for __c_anonymous_ifk_data {}
3076-
3077-
impl fmt::Debug for __c_anonymous_ifk_data {
3078-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3079-
f.debug_struct("__c_anonymous_ifk_data")
3080-
.field("ifk_ptr", unsafe { &self.ifk_ptr })
3081-
.field("ifk_value", unsafe { &self.ifk_value })
3082-
.finish()
3083-
}
3084-
}
30853069
impl hash::Hash for __c_anonymous_ifk_data {
30863070
fn hash<H: hash::Hasher>(&self, state: &mut H) {
30873071
unsafe {
@@ -3144,31 +3128,6 @@ cfg_if! {
31443128

31453129
impl Eq for __c_anonymous_ifr_ifru {}
31463130

3147-
impl fmt::Debug for __c_anonymous_ifr_ifru {
3148-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3149-
f.debug_struct("__c_anonymous_ifr_ifru")
3150-
.field("ifru_addr", unsafe { &self.ifru_addr })
3151-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
3152-
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
3153-
.field("ifru_flags", unsafe { &self.ifru_flags })
3154-
.field("ifru_metrics", unsafe { &self.ifru_metrics })
3155-
.field("ifru_mtu", unsafe { &self.ifru_mtu })
3156-
.field("ifru_phys", unsafe { &self.ifru_phys })
3157-
.field("ifru_media", unsafe { &self.ifru_media })
3158-
.field("ifru_intval", unsafe { &self.ifru_intval })
3159-
.field("ifru_data", unsafe { &self.ifru_data })
3160-
.field("ifru_devmtu", unsafe { &self.ifru_devmtu })
3161-
.field("ifru_kpi", unsafe { &self.ifru_kpi })
3162-
.field("ifru_wake_flags", unsafe { &self.ifru_wake_flags })
3163-
.field("ifru_route_refcnt", unsafe { &self.ifru_route_refcnt })
3164-
.field("ifru_cap", unsafe { &self.ifru_cap })
3165-
.field("ifru_functional_type", unsafe {
3166-
&self.ifru_functional_type
3167-
})
3168-
.finish()
3169-
}
3170-
}
3171-
31723131
impl hash::Hash for __c_anonymous_ifr_ifru {
31733132
fn hash<H: hash::Hasher>(&self, state: &mut H) {
31743133
unsafe {
@@ -3224,15 +3183,6 @@ cfg_if! {
32243183
}
32253184
}
32263185

3227-
impl fmt::Debug for __c_anonymous_ifc_ifcu {
3228-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3229-
f.debug_struct("ifc_ifcu")
3230-
.field("ifcu_buf", unsafe { &self.ifcu_buf })
3231-
.field("ifcu_req", unsafe { &self.ifcu_req })
3232-
.finish()
3233-
}
3234-
}
3235-
32363186
impl hash::Hash for __c_anonymous_ifc_ifcu {
32373187
fn hash<H: hash::Hasher>(&self, state: &mut H) {
32383188
unsafe { self.ifcu_buf.hash(state) };
@@ -3261,21 +3211,6 @@ cfg_if! {
32613211

32623212
impl Eq for __c_anonymous_ifr_ifru6 {}
32633213

3264-
impl fmt::Debug for __c_anonymous_ifr_ifru6 {
3265-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3266-
f.debug_struct("__c_anonymous_ifr_ifru6")
3267-
.field("ifru_addr", unsafe { &self.ifru_addr })
3268-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
3269-
.field("ifru_flags", unsafe { &self.ifru_flags })
3270-
.field("ifru_flags6", unsafe { &self.ifru_flags6 })
3271-
.field("ifru_metrics", unsafe { &self.ifru_metrics })
3272-
.field("ifru_intval", unsafe { &self.ifru_intval })
3273-
.field("ifru_data", unsafe { &self.ifru_data })
3274-
.field("ifru_scope_id", unsafe { &self.ifru_scope_id })
3275-
.finish()
3276-
}
3277-
}
3278-
32793214
impl hash::Hash for __c_anonymous_ifr_ifru6 {
32803215
fn hash<H: hash::Hasher>(&self, state: &mut H) {
32813216
unsafe {

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

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,13 +1698,6 @@ cfg_if! {
16981698
}
16991699
}
17001700
impl Eq for __c_anonymous_cr_pid {}
1701-
impl fmt::Debug for __c_anonymous_cr_pid {
1702-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1703-
f.debug_struct("cr_pid")
1704-
.field("cr_pid", unsafe { &self.cr_pid })
1705-
.finish()
1706-
}
1707-
}
17081701
impl hash::Hash for __c_anonymous_cr_pid {
17091702
fn hash<H: hash::Hasher>(&self, state: &mut H) {
17101703
unsafe { self.cr_pid.hash(state) };
@@ -1876,13 +1869,6 @@ cfg_if! {
18761869
}
18771870
}
18781871
impl Eq for __c_anonymous_elf32_auxv_union {}
1879-
impl fmt::Debug for __c_anonymous_elf32_auxv_union {
1880-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1881-
f.debug_struct("a_val")
1882-
.field("a_val", unsafe { &self.a_val })
1883-
.finish()
1884-
}
1885-
}
18861872
impl PartialEq for Elf32_Auxinfo {
18871873
fn eq(&self, other: &Elf32_Auxinfo) -> bool {
18881874
self.a_type == other.a_type && self.a_un == other.a_un
@@ -1920,27 +1906,6 @@ cfg_if! {
19201906
}
19211907
}
19221908
impl Eq for __c_anonymous_ifr_ifru {}
1923-
impl fmt::Debug for __c_anonymous_ifr_ifru {
1924-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1925-
f.debug_struct("ifr_ifru")
1926-
.field("ifru_addr", unsafe { &self.ifru_addr })
1927-
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
1928-
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
1929-
.field("ifru_buffer", unsafe { &self.ifru_buffer })
1930-
.field("ifru_flags", unsafe { &self.ifru_flags })
1931-
.field("ifru_index", unsafe { &self.ifru_index })
1932-
.field("ifru_jid", unsafe { &self.ifru_jid })
1933-
.field("ifru_metric", unsafe { &self.ifru_metric })
1934-
.field("ifru_mtu", unsafe { &self.ifru_mtu })
1935-
.field("ifru_phys", unsafe { &self.ifru_phys })
1936-
.field("ifru_media", unsafe { &self.ifru_media })
1937-
.field("ifru_data", unsafe { &self.ifru_data })
1938-
.field("ifru_cap", unsafe { &self.ifru_cap })
1939-
.field("ifru_fib", unsafe { &self.ifru_fib })
1940-
.field("ifru_vlan_pcp", unsafe { &self.ifru_vlan_pcp })
1941-
.finish()
1942-
}
1943-
}
19441909
impl hash::Hash for __c_anonymous_ifr_ifru {
19451910
fn hash<H: hash::Hasher>(&self, state: &mut H) {
19461911
unsafe { self.ifru_addr.hash(state) };
@@ -1990,15 +1955,6 @@ cfg_if! {
19901955
}
19911956
}
19921957

1993-
impl fmt::Debug for __c_anonymous_ifc_ifcu {
1994-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1995-
f.debug_struct("ifc_ifcu")
1996-
.field("ifcu_buf", unsafe { &self.ifcu_buf })
1997-
.field("ifcu_req", unsafe { &self.ifcu_req })
1998-
.finish()
1999-
}
2000-
}
2001-
20021958
impl hash::Hash for __c_anonymous_ifc_ifcu {
20031959
fn hash<H: hash::Hasher>(&self, state: &mut H) {
20041960
unsafe { self.ifcu_buf.hash(state) };
@@ -2107,14 +2063,6 @@ cfg_if! {
21072063
}
21082064
}
21092065
impl Eq for __c_anonymous_ifi_epoch {}
2110-
impl fmt::Debug for __c_anonymous_ifi_epoch {
2111-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2112-
f.debug_struct("__c_anonymous_ifi_epoch")
2113-
.field("tt", unsafe { &self.tt })
2114-
.field("ph", unsafe { &self.ph })
2115-
.finish()
2116-
}
2117-
}
21182066
impl hash::Hash for __c_anonymous_ifi_epoch {
21192067
fn hash<H: hash::Hasher>(&self, state: &mut H) {
21202068
unsafe {
@@ -2130,14 +2078,6 @@ cfg_if! {
21302078
}
21312079
}
21322080
impl Eq for __c_anonymous_ifi_lastchange {}
2133-
impl fmt::Debug for __c_anonymous_ifi_lastchange {
2134-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2135-
f.debug_struct("__c_anonymous_ifi_lastchange")
2136-
.field("tv", unsafe { &self.tv })
2137-
.field("ph", unsafe { &self.ph })
2138-
.finish()
2139-
}
2140-
}
21412081
impl hash::Hash for __c_anonymous_ifi_lastchange {
21422082
fn hash<H: hash::Hasher>(&self, state: &mut H) {
21432083
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)