Skip to content

Commit f332c21

Browse files
authored
Merge pull request #4471 from tgross35/no-handwritten-debug
Replace handwritten `Debug` impls with derives
2 parents 2324acf + 65c39bf commit f332c21

File tree

60 files changed

+16
-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.

60 files changed

+16
-3333
lines changed

libc-test/build.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,9 +5548,9 @@ fn test_aix(target: &str) {
55485548
});
55495549

55505550
cfg.type_name(move |ty, is_struct, is_union| match ty {
5551-
"DIR" => ty.to_string(),
5552-
"FILE" => ty.to_string(),
5553-
"ACTION" => ty.to_string(),
5551+
"DIR" => ty.to_string(),
5552+
"FILE" => ty.to_string(),
5553+
"ACTION" => ty.to_string(),
55545554

55555555
// 'sigval' is a struct in Rust, but a union in C.
55565556
"sigval" => format!("union sigval"),
@@ -5637,9 +5637,9 @@ fn test_aix(target: &str) {
56375637
// POSIX-compliant versions in the system libc. As a result,
56385638
// function pointer comparisons between the C and Rust sides
56395639
// would fail.
5640-
"getpwuid_r" | "getpwnam_r" | "getgrgid_r" | "getgrnam_r"
5641-
| "aio_cancel" | "aio_error" | "aio_fsync" | "aio_read"
5642-
| "aio_return" | "aio_suspend" | "aio_write" | "select" => true,
5640+
"getpwuid_r" | "getpwnam_r" | "getgrgid_r" | "getgrnam_r" | "aio_cancel"
5641+
| "aio_error" | "aio_fsync" | "aio_read" | "aio_return" | "aio_suspend"
5642+
| "aio_write" | "select" => true,
56435643

56445644
// 'getdtablesize' is a constant in the AIX header but it is
56455645
// a real function in libc which the Rust side is resolved to.
@@ -5656,7 +5656,6 @@ fn test_aix(target: &str) {
56565656
}
56575657
});
56585658

5659-
56605659
cfg.volatile_item(|i| {
56615660
use ctest::VolatileItemKind::*;
56625661
match i {

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: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::in_addr_t;
2-
use crate::in_port_t;
31
use crate::prelude::*;
2+
use crate::{in_addr_t, in_port_t};
43

54
pub type caddr_t = *mut c_char;
65
pub type clockid_t = c_longlong;
@@ -582,18 +581,6 @@ cfg_if! {
582581
}
583582
}
584583
impl Eq for poll_ctl_ext {}
585-
impl fmt::Debug for poll_ctl_ext {
586-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
587-
f.debug_struct("poll_ctl_ext")
588-
.field("version", &self.version)
589-
.field("command", &self.command)
590-
.field("events", &self.events)
591-
.field("fd", &self.fd)
592-
.field("u", &self.u)
593-
.field("reserved64", &self.reserved64)
594-
.finish()
595-
}
596-
}
597584
impl hash::Hash for poll_ctl_ext {
598585
fn hash<H: hash::Hasher>(&self, state: &mut H) {
599586
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);

0 commit comments

Comments
 (0)