Skip to content

Commit 54fa73e

Browse files
committed
Replace handwritten Debug impls with derives
`s_no_extra_traits!` doesn't derive `Debug` so there are a lot of handwritten implementations. However, since we have a derive-like solution for unions now (printing them like an opaque struct), there really isn't any reason these can't all be derived. Add `derive(Debug)` to `s_no_extra_traits`, still gated behind `feature = "extra_traits"`, which allows getting rid of manual implementations. (backport <#4471>) (cherry picked from commit 65c39bf)
1 parent 44b29ed commit 54fa73e

File tree

59 files changed

+9
-3333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+9
-3333
lines changed

libc-test/test/cmsg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod t {
7070
for cmsg_len in 0..64 {
7171
// Address must be a multiple of 0x4 for testing on AIX.
7272
if cfg!(target_os = "aix") && cmsg_len % std::mem::size_of::<cmsghdr>() != 0 {
73-
continue;
73+
continue;
7474
}
7575
for next_cmsg_len in 0..32 {
7676
unsafe {

src/fuchsia/mod.rs

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,26 +1068,6 @@ cfg_if! {
10681068
}
10691069
}
10701070
impl Eq for sysinfo {}
1071-
impl fmt::Debug for sysinfo {
1072-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1073-
f.debug_struct("sysinfo")
1074-
.field("uptime", &self.uptime)
1075-
.field("loads", &self.loads)
1076-
.field("totalram", &self.totalram)
1077-
.field("freeram", &self.freeram)
1078-
.field("sharedram", &self.sharedram)
1079-
.field("bufferram", &self.bufferram)
1080-
.field("totalswap", &self.totalswap)
1081-
.field("freeswap", &self.freeswap)
1082-
.field("procs", &self.procs)
1083-
.field("pad", &self.pad)
1084-
.field("totalhigh", &self.totalhigh)
1085-
.field("freehigh", &self.freehigh)
1086-
.field("mem_unit", &self.mem_unit)
1087-
// FIXME(debug): .field("__reserved", &self.__reserved)
1088-
.finish()
1089-
}
1090-
}
10911071
impl hash::Hash for sysinfo {
10921072
fn hash<H: hash::Hasher>(&self, state: &mut H) {
10931073
self.uptime.hash(state);
@@ -1118,14 +1098,6 @@ cfg_if! {
11181098
}
11191099
}
11201100
impl Eq for sockaddr_un {}
1121-
impl fmt::Debug for sockaddr_un {
1122-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1123-
f.debug_struct("sockaddr_un")
1124-
.field("sun_family", &self.sun_family)
1125-
// FIXME(debug): .field("sun_path", &self.sun_path)
1126-
.finish()
1127-
}
1128-
}
11291101
impl hash::Hash for sockaddr_un {
11301102
fn hash<H: hash::Hasher>(&self, state: &mut H) {
11311103
self.sun_family.hash(state);
@@ -1145,15 +1117,6 @@ cfg_if! {
11451117
}
11461118
}
11471119
impl Eq for sockaddr_storage {}
1148-
impl fmt::Debug for sockaddr_storage {
1149-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1150-
f.debug_struct("sockaddr_storage")
1151-
.field("ss_family", &self.ss_family)
1152-
.field("__ss_align", &self.__ss_align)
1153-
// FIXME(debug): .field("__ss_pad2", &self.__ss_pad2)
1154-
.finish()
1155-
}
1156-
}
11571120
impl hash::Hash for sockaddr_storage {
11581121
fn hash<H: hash::Hasher>(&self, state: &mut H) {
11591122
self.ss_family.hash(state);
@@ -1191,17 +1154,6 @@ cfg_if! {
11911154
}
11921155
}
11931156
impl Eq for utsname {}
1194-
impl fmt::Debug for utsname {
1195-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1196-
f.debug_struct("utsname")
1197-
// FIXME(debug): .field("sysname", &self.sysname)
1198-
// FIXME(debug): .field("nodename", &self.nodename)
1199-
// FIXME(debug): .field("release", &self.release)
1200-
// FIXME(debug): .field("version", &self.version)
1201-
// FIXME(debug): .field("machine", &self.machine)
1202-
.finish()
1203-
}
1204-
}
12051157
impl hash::Hash for utsname {
12061158
fn hash<H: hash::Hasher>(&self, state: &mut H) {
12071159
self.sysname.hash(state);
@@ -1226,17 +1178,6 @@ cfg_if! {
12261178
}
12271179
}
12281180
impl Eq for dirent {}
1229-
impl fmt::Debug for dirent {
1230-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1231-
f.debug_struct("dirent")
1232-
.field("d_ino", &self.d_ino)
1233-
.field("d_off", &self.d_off)
1234-
.field("d_reclen", &self.d_reclen)
1235-
.field("d_type", &self.d_type)
1236-
// FIXME(debug): .field("d_name", &self.d_name)
1237-
.finish()
1238-
}
1239-
}
12401181
impl hash::Hash for dirent {
12411182
fn hash<H: hash::Hasher>(&self, state: &mut H) {
12421183
self.d_ino.hash(state);
@@ -1261,17 +1202,6 @@ cfg_if! {
12611202
}
12621203
}
12631204
impl Eq for dirent64 {}
1264-
impl fmt::Debug for dirent64 {
1265-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1266-
f.debug_struct("dirent64")
1267-
.field("d_ino", &self.d_ino)
1268-
.field("d_off", &self.d_off)
1269-
.field("d_reclen", &self.d_reclen)
1270-
.field("d_type", &self.d_type)
1271-
// FIXME(debug): .field("d_name", &self.d_name)
1272-
.finish()
1273-
}
1274-
}
12751205
impl hash::Hash for dirent64 {
12761206
fn hash<H: hash::Hasher>(&self, state: &mut H) {
12771207
self.d_ino.hash(state);
@@ -1291,16 +1221,6 @@ cfg_if! {
12911221
}
12921222
}
12931223
impl Eq for mq_attr {}
1294-
impl fmt::Debug for mq_attr {
1295-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1296-
f.debug_struct("mq_attr")
1297-
.field("mq_flags", &self.mq_flags)
1298-
.field("mq_maxmsg", &self.mq_maxmsg)
1299-
.field("mq_msgsize", &self.mq_msgsize)
1300-
.field("mq_curmsgs", &self.mq_curmsgs)
1301-
.finish()
1302-
}
1303-
}
13041224
impl hash::Hash for mq_attr {
13051225
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13061226
self.mq_flags.hash(state);
@@ -1318,15 +1238,6 @@ cfg_if! {
13181238
}
13191239
}
13201240
impl Eq for sockaddr_nl {}
1321-
impl fmt::Debug for sockaddr_nl {
1322-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1323-
f.debug_struct("sockaddr_nl")
1324-
.field("nl_family", &self.nl_family)
1325-
.field("nl_pid", &self.nl_pid)
1326-
.field("nl_groups", &self.nl_groups)
1327-
.finish()
1328-
}
1329-
}
13301241
impl hash::Hash for sockaddr_nl {
13311242
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13321243
self.nl_family.hash(state);
@@ -1347,17 +1258,6 @@ cfg_if! {
13471258
}
13481259
}
13491260
impl Eq for sigevent {}
1350-
impl fmt::Debug for sigevent {
1351-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1352-
f.debug_struct("sigevent")
1353-
.field("sigev_value", &self.sigev_value)
1354-
.field("sigev_signo", &self.sigev_signo)
1355-
.field("sigev_notify", &self.sigev_notify)
1356-
.field("sigev_notify_function", &self.sigev_notify_function)
1357-
.field("sigev_notify_attributes", &self.sigev_notify_attributes)
1358-
.finish()
1359-
}
1360-
}
13611261
impl hash::Hash for sigevent {
13621262
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13631263
self.sigev_value.hash(state);
@@ -1374,13 +1274,6 @@ cfg_if! {
13741274
}
13751275
}
13761276
impl Eq for pthread_cond_t {}
1377-
impl fmt::Debug for pthread_cond_t {
1378-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1379-
f.debug_struct("pthread_cond_t")
1380-
// FIXME(debug): .field("size", &self.size)
1381-
.finish()
1382-
}
1383-
}
13841277
impl hash::Hash for pthread_cond_t {
13851278
fn hash<H: hash::Hasher>(&self, state: &mut H) {
13861279
self.size.hash(state);
@@ -1393,13 +1286,6 @@ cfg_if! {
13931286
}
13941287
}
13951288
impl Eq for pthread_mutex_t {}
1396-
impl fmt::Debug for pthread_mutex_t {
1397-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1398-
f.debug_struct("pthread_mutex_t")
1399-
// FIXME(debug): .field("size", &self.size)
1400-
.finish()
1401-
}
1402-
}
14031289
impl hash::Hash for pthread_mutex_t {
14041290
fn hash<H: hash::Hasher>(&self, state: &mut H) {
14051291
self.size.hash(state);
@@ -1412,13 +1298,6 @@ cfg_if! {
14121298
}
14131299
}
14141300
impl Eq for pthread_rwlock_t {}
1415-
impl fmt::Debug for pthread_rwlock_t {
1416-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1417-
f.debug_struct("pthread_rwlock_t")
1418-
// FIXME(debug): .field("size", &self.size)
1419-
.finish()
1420-
}
1421-
}
14221301
impl hash::Hash for pthread_rwlock_t {
14231302
fn hash<H: hash::Hasher>(&self, state: &mut H) {
14241303
self.size.hash(state);

src/fuchsia/x86_64.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ cfg_if! {
9494
}
9595
}
9696
impl Eq for ucontext_t {}
97-
impl fmt::Debug for ucontext_t {
98-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
99-
f.debug_struct("ucontext_t")
100-
.field("uc_flags", &self.uc_flags)
101-
.field("uc_link", &self.uc_link)
102-
.field("uc_stack", &self.uc_stack)
103-
.field("uc_mcontext", &self.uc_mcontext)
104-
.field("uc_sigmask", &self.uc_sigmask)
105-
// FIXME(debug): .field("__private", &self.__private)
106-
.finish()
107-
}
108-
}
10997
impl hash::Hash for ucontext_t {
11098
fn hash<H: hash::Hasher>(&self, state: &mut H) {
11199
self.uc_flags.hash(state);

src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ macro_rules! s_paren {
141141
)*);
142142
}
143143

144-
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature.
144+
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug`
145+
/// with `extra_traits` since that can always be derived.
145146
///
146147
/// Most items will prefer to use [`s`].
147148
macro_rules! s_no_extra_traits {
@@ -172,6 +173,7 @@ macro_rules! s_no_extra_traits {
172173
__item! {
173174
#[repr(C)]
174175
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
176+
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
175177
$(#[$attr])*
176178
pub struct $i { $($field)* }
177179
}

src/unix/aix/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,18 +581,6 @@ cfg_if! {
581581
}
582582
}
583583
impl Eq for poll_ctl_ext {}
584-
impl fmt::Debug for poll_ctl_ext {
585-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
586-
f.debug_struct("poll_ctl_ext")
587-
.field("version", &self.version)
588-
.field("command", &self.command)
589-
.field("events", &self.events)
590-
.field("fd", &self.fd)
591-
.field("u", &self.u)
592-
.field("reserved64", &self.reserved64)
593-
.finish()
594-
}
595-
}
596584
impl hash::Hash for poll_ctl_ext {
597585
fn hash<H: hash::Hasher>(&self, state: &mut H) {
598586
self.version.hash(state);

src/unix/aix/powerpc64.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,6 @@ cfg_if! {
313313
}
314314
}
315315
impl Eq for siginfo_t {}
316-
impl fmt::Debug for siginfo_t {
317-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
318-
f.debug_struct("siginfo_t")
319-
.field("si_signo", &self.si_signo)
320-
.field("si_errno", &self.si_errno)
321-
.field("si_code", &self.si_code)
322-
.field("si_pid", &self.si_pid)
323-
.field("si_uid", &self.si_uid)
324-
.field("si_status", &self.si_status)
325-
.field("si_addr", &self.si_addr)
326-
.field("si_band", &self.si_band)
327-
.field("si_value", &self.si_value)
328-
.field("__si_flags", &self.__si_flags)
329-
.finish()
330-
}
331-
}
332316
impl hash::Hash for siginfo_t {
333317
fn hash<H: hash::Hasher>(&self, state: &mut H) {
334318
self.si_signo.hash(state);
@@ -372,16 +356,6 @@ cfg_if! {
372356
}
373357
}
374358
impl Eq for pollfd_ext {}
375-
impl fmt::Debug for pollfd_ext {
376-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
377-
f.debug_struct("pollfd_ext")
378-
.field("fd", &self.fd)
379-
.field("events", &self.events)
380-
.field("revents", &self.revents)
381-
.field("data", &self.data)
382-
.finish()
383-
}
384-
}
385359
impl hash::Hash for pollfd_ext {
386360
fn hash<H: hash::Hasher>(&self, state: &mut H) {
387361
self.fd.hash(state);
@@ -398,12 +372,6 @@ cfg_if! {
398372

399373
impl Eq for fpreg_t {}
400374

401-
impl fmt::Debug for fpreg_t {
402-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403-
f.debug_struct("fpreg_t").field("d", &self.d).finish()
404-
}
405-
}
406-
407375
impl hash::Hash for fpreg_t {
408376
fn hash<H: hash::Hasher>(&self, state: &mut H) {
409377
let d: u64 = unsafe { mem::transmute(self.d) };

src/unix/bsd/apple/b32/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ cfg_if! {
8080
}
8181
}
8282
impl Eq for pthread_attr_t {}
83-
impl fmt::Debug for pthread_attr_t {
84-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85-
f.debug_struct("pthread_attr_t")
86-
.field("__sig", &self.__sig)
87-
// FIXME(debug): .field("__opaque", &self.__opaque)
88-
.finish()
89-
}
90-
}
9183
impl hash::Hash for pthread_attr_t {
9284
fn hash<H: hash::Hasher>(&self, state: &mut H) {
9385
self.__sig.hash(state);
@@ -105,13 +97,6 @@ cfg_if! {
10597
}
10698
}
10799
impl Eq for pthread_once_t {}
108-
impl fmt::Debug for pthread_once_t {
109-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110-
f.debug_struct("pthread_once_t")
111-
.field("__sig", &self.__sig)
112-
.finish()
113-
}
114-
}
115100
impl hash::Hash for pthread_once_t {
116101
fn hash<H: hash::Hasher>(&self, state: &mut H) {
117102
self.__sig.hash(state);

src/unix/bsd/apple/b64/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ cfg_if! {
7373
}
7474
}
7575
impl Eq for pthread_attr_t {}
76-
impl fmt::Debug for pthread_attr_t {
77-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78-
f.debug_struct("pthread_attr_t")
79-
.field("__sig", &self.__sig)
80-
// FIXME(debug): .field("__opaque", &self.__opaque)
81-
.finish()
82-
}
83-
}
8476
impl hash::Hash for pthread_attr_t {
8577
fn hash<H: hash::Hasher>(&self, state: &mut H) {
8678
self.__sig.hash(state);
@@ -98,13 +90,6 @@ cfg_if! {
9890
}
9991
}
10092
impl Eq for pthread_once_t {}
101-
impl fmt::Debug for pthread_once_t {
102-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
103-
f.debug_struct("pthread_once_t")
104-
.field("__sig", &self.__sig)
105-
.finish()
106-
}
107-
}
10893
impl hash::Hash for pthread_once_t {
10994
fn hash<H: hash::Hasher>(&self, state: &mut H) {
11095
self.__sig.hash(state);

0 commit comments

Comments
 (0)