Skip to content

Replace handwritten Debug impls with derives #4471

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

Merged
merged 1 commit into from
Jun 2, 2025
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
13 changes: 6 additions & 7 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5548,9 +5548,9 @@ fn test_aix(target: &str) {
});

cfg.type_name(move |ty, is_struct, is_union| match ty {
"DIR" => ty.to_string(),
"FILE" => ty.to_string(),
"ACTION" => ty.to_string(),
"DIR" => ty.to_string(),
"FILE" => ty.to_string(),
"ACTION" => ty.to_string(),

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

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


cfg.volatile_item(|i| {
use ctest::VolatileItemKind::*;
match i {
Expand Down
2 changes: 1 addition & 1 deletion libc-test/test/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod t {
for cmsg_len in 0..64 {
// Address must be a multiple of 0x4 for testing on AIX.
if cfg!(target_os = "aix") && cmsg_len % std::mem::size_of::<cmsghdr>() != 0 {
continue;
continue;
}
for next_cmsg_len in 0..32 {
unsafe {
Expand Down
121 changes: 0 additions & 121 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,26 +1068,6 @@ cfg_if! {
}
}
impl Eq for sysinfo {}
impl fmt::Debug for sysinfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("sysinfo")
.field("uptime", &self.uptime)
.field("loads", &self.loads)
.field("totalram", &self.totalram)
.field("freeram", &self.freeram)
.field("sharedram", &self.sharedram)
.field("bufferram", &self.bufferram)
.field("totalswap", &self.totalswap)
.field("freeswap", &self.freeswap)
.field("procs", &self.procs)
.field("pad", &self.pad)
.field("totalhigh", &self.totalhigh)
.field("freehigh", &self.freehigh)
.field("mem_unit", &self.mem_unit)
// FIXME(debug): .field("__reserved", &self.__reserved)
.finish()
}
}
impl hash::Hash for sysinfo {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.uptime.hash(state);
Expand Down Expand Up @@ -1118,14 +1098,6 @@ cfg_if! {
}
}
impl Eq for sockaddr_un {}
impl fmt::Debug for sockaddr_un {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("sockaddr_un")
.field("sun_family", &self.sun_family)
// FIXME(debug): .field("sun_path", &self.sun_path)
.finish()
}
}
impl hash::Hash for sockaddr_un {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.sun_family.hash(state);
Expand All @@ -1145,15 +1117,6 @@ cfg_if! {
}
}
impl Eq for sockaddr_storage {}
impl fmt::Debug for sockaddr_storage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("sockaddr_storage")
.field("ss_family", &self.ss_family)
.field("__ss_align", &self.__ss_align)
// FIXME(debug): .field("__ss_pad2", &self.__ss_pad2)
.finish()
}
}
impl hash::Hash for sockaddr_storage {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.ss_family.hash(state);
Expand Down Expand Up @@ -1191,17 +1154,6 @@ cfg_if! {
}
}
impl Eq for utsname {}
impl fmt::Debug for utsname {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("utsname")
// FIXME(debug): .field("sysname", &self.sysname)
// FIXME(debug): .field("nodename", &self.nodename)
// FIXME(debug): .field("release", &self.release)
// FIXME(debug): .field("version", &self.version)
// FIXME(debug): .field("machine", &self.machine)
.finish()
}
}
impl hash::Hash for utsname {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.sysname.hash(state);
Expand All @@ -1226,17 +1178,6 @@ cfg_if! {
}
}
impl Eq for dirent {}
impl fmt::Debug for dirent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("dirent")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
// FIXME(debug): .field("d_name", &self.d_name)
.finish()
}
}
impl hash::Hash for dirent {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.d_ino.hash(state);
Expand All @@ -1261,17 +1202,6 @@ cfg_if! {
}
}
impl Eq for dirent64 {}
impl fmt::Debug for dirent64 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("dirent64")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
// FIXME(debug): .field("d_name", &self.d_name)
.finish()
}
}
impl hash::Hash for dirent64 {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.d_ino.hash(state);
Expand All @@ -1291,16 +1221,6 @@ cfg_if! {
}
}
impl Eq for mq_attr {}
impl fmt::Debug for mq_attr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
.field("mq_msgsize", &self.mq_msgsize)
.field("mq_curmsgs", &self.mq_curmsgs)
.finish()
}
}
impl hash::Hash for mq_attr {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.mq_flags.hash(state);
Expand All @@ -1318,15 +1238,6 @@ cfg_if! {
}
}
impl Eq for sockaddr_nl {}
impl fmt::Debug for sockaddr_nl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("sockaddr_nl")
.field("nl_family", &self.nl_family)
.field("nl_pid", &self.nl_pid)
.field("nl_groups", &self.nl_groups)
.finish()
}
}
impl hash::Hash for sockaddr_nl {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.nl_family.hash(state);
Expand All @@ -1347,17 +1258,6 @@ cfg_if! {
}
}
impl Eq for sigevent {}
impl fmt::Debug for sigevent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("sigevent")
.field("sigev_value", &self.sigev_value)
.field("sigev_signo", &self.sigev_signo)
.field("sigev_notify", &self.sigev_notify)
.field("sigev_notify_function", &self.sigev_notify_function)
.field("sigev_notify_attributes", &self.sigev_notify_attributes)
.finish()
}
}
impl hash::Hash for sigevent {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.sigev_value.hash(state);
Expand All @@ -1374,13 +1274,6 @@ cfg_if! {
}
}
impl Eq for pthread_cond_t {}
impl fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("pthread_cond_t")
// FIXME(debug): .field("size", &self.size)
.finish()
}
}
impl hash::Hash for pthread_cond_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
Expand All @@ -1393,13 +1286,6 @@ cfg_if! {
}
}
impl Eq for pthread_mutex_t {}
impl fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("pthread_mutex_t")
// FIXME(debug): .field("size", &self.size)
.finish()
}
}
impl hash::Hash for pthread_mutex_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
Expand All @@ -1412,13 +1298,6 @@ cfg_if! {
}
}
impl Eq for pthread_rwlock_t {}
impl fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("pthread_rwlock_t")
// FIXME(debug): .field("size", &self.size)
.finish()
}
}
impl hash::Hash for pthread_rwlock_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
Expand Down
12 changes: 0 additions & 12 deletions src/fuchsia/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ cfg_if! {
}
}
impl Eq for ucontext_t {}
impl fmt::Debug for ucontext_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ucontext_t")
.field("uc_flags", &self.uc_flags)
.field("uc_link", &self.uc_link)
.field("uc_stack", &self.uc_stack)
.field("uc_mcontext", &self.uc_mcontext)
.field("uc_sigmask", &self.uc_sigmask)
// FIXME(debug): .field("__private", &self.__private)
.finish()
}
}
impl hash::Hash for ucontext_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.uc_flags.hash(state);
Expand Down
4 changes: 3 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ macro_rules! s_paren {
)*);
}

/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature.
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug`
/// with `extra_traits` since that can always be derived.
///
/// Most items will prefer to use [`s`].
macro_rules! s_no_extra_traits {
Expand Down Expand Up @@ -172,6 +173,7 @@ macro_rules! s_no_extra_traits {
__item! {
#[repr(C)]
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
$(#[$attr])*
pub struct $i { $($field)* }
}
Expand Down
15 changes: 1 addition & 14 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::in_addr_t;
use crate::in_port_t;
use crate::prelude::*;
use crate::{in_addr_t, in_port_t};

pub type caddr_t = *mut c_char;
pub type clockid_t = c_longlong;
Expand Down Expand Up @@ -582,18 +581,6 @@ cfg_if! {
}
}
impl Eq for poll_ctl_ext {}
impl fmt::Debug for poll_ctl_ext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("poll_ctl_ext")
.field("version", &self.version)
.field("command", &self.command)
.field("events", &self.events)
.field("fd", &self.fd)
.field("u", &self.u)
.field("reserved64", &self.reserved64)
.finish()
}
}
impl hash::Hash for poll_ctl_ext {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.version.hash(state);
Expand Down
32 changes: 0 additions & 32 deletions src/unix/aix/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,6 @@ cfg_if! {
}
}
impl Eq for siginfo_t {}
impl fmt::Debug for siginfo_t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("siginfo_t")
.field("si_signo", &self.si_signo)
.field("si_errno", &self.si_errno)
.field("si_code", &self.si_code)
.field("si_pid", &self.si_pid)
.field("si_uid", &self.si_uid)
.field("si_status", &self.si_status)
.field("si_addr", &self.si_addr)
.field("si_band", &self.si_band)
.field("si_value", &self.si_value)
.field("__si_flags", &self.__si_flags)
.finish()
}
}
impl hash::Hash for siginfo_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.si_signo.hash(state);
Expand Down Expand Up @@ -372,16 +356,6 @@ cfg_if! {
}
}
impl Eq for pollfd_ext {}
impl fmt::Debug for pollfd_ext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("pollfd_ext")
.field("fd", &self.fd)
.field("events", &self.events)
.field("revents", &self.revents)
.field("data", &self.data)
.finish()
}
}
impl hash::Hash for pollfd_ext {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.fd.hash(state);
Expand All @@ -398,12 +372,6 @@ cfg_if! {

impl Eq for fpreg_t {}

impl fmt::Debug for fpreg_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("fpreg_t").field("d", &self.d).finish()
}
}

impl hash::Hash for fpreg_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
let d: u64 = unsafe { mem::transmute(self.d) };
Expand Down
15 changes: 0 additions & 15 deletions src/unix/bsd/apple/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ cfg_if! {
}
}
impl Eq for pthread_attr_t {}
impl fmt::Debug for pthread_attr_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("pthread_attr_t")
.field("__sig", &self.__sig)
// FIXME(debug): .field("__opaque", &self.__opaque)
.finish()
}
}
impl hash::Hash for pthread_attr_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.__sig.hash(state);
Expand All @@ -105,13 +97,6 @@ cfg_if! {
}
}
impl Eq for pthread_once_t {}
impl fmt::Debug for pthread_once_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("pthread_once_t")
.field("__sig", &self.__sig)
.finish()
}
}
impl hash::Hash for pthread_once_t {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.__sig.hash(state);
Expand Down
Loading
Loading