Skip to content

Commit d9a17c6

Browse files
committed
Always implement Debug
Currently `Debug` implementations are gated behind the `extra-traits` feature. My understanding is that historically, this was for two reasons: 1. `Debug` implementations for unions were unsound 2. Concerns about compile time The first was resolved a while ago by adding a "manual derive" opaque implementation, in 6faa521 ("fix: make Debug impl for unions opaque"). Regarding the second reason, compile times for the current `main` on my machine are (cleaning in between, with the 2025-08-06 nightly): $ cargo build -p libc Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.79s $ cargo build -p libc --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.64s $ cargo build -p libc --features extra_traits Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.08s $ cargo build -p libc --features extra_traits --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.85s And with this patch applied: $ cargo build -p libc Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s $ cargo build -p libc --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.70s $ cargo build -p libc --features extra_traits Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.15s $ cargo build -p libc --features extra_traits --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.86s That is a microbenchmark but it shows that there probably isn't anything to worry about. Thus, remove the `Debug` implementation from the `feature = "extra_traitts"` gating. Another advantage of doing this is that it should allow many crates to remove the enable for `extra_traits`, giving us a better idea of who wants `Debug` vs. who is actually using the `Eq`/`Hash` implementations. Link: #3880
1 parent 458c5a0 commit d9a17c6

File tree

24 files changed

+62
-52
lines changed

24 files changed

+62
-52
lines changed

src/fuchsia/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ pub type rlim_t = c_ulonglong;
8080

8181
// FIXME(fuchsia): why are these uninhabited types? that seems... wrong?
8282
// Presumably these should be `()` or an `extern type` (when that stabilizes).
83-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
83+
#[derive(Debug)]
8484
pub enum timezone {}
8585
impl Copy for timezone {}
8686
impl Clone for timezone {
8787
fn clone(&self) -> timezone {
8888
*self
8989
}
9090
}
91-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
91+
#[derive(Debug)]
9292
pub enum DIR {}
9393
impl Copy for DIR {}
9494
impl Clone for DIR {
@@ -97,7 +97,7 @@ impl Clone for DIR {
9797
}
9898
}
9999

100-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
100+
#[derive(Debug)]
101101
pub enum fpos64_t {} // FIXME(fuchsia): fill this out with a struct
102102
impl Copy for fpos64_t {}
103103
impl Clone for fpos64_t {
@@ -3421,15 +3421,15 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
34213421
#[link(name = "fdio")]
34223422
extern "C" {}
34233423

3424-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3424+
#[derive(Debug)]
34253425
pub enum FILE {}
34263426
impl Copy for FILE {}
34273427
impl Clone for FILE {
34283428
fn clone(&self) -> FILE {
34293429
*self
34303430
}
34313431
}
3432-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3432+
#[derive(Debug)]
34333433
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
34343434
impl Copy for fpos_t {}
34353435
impl Clone for fpos_t {

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
// Attributes needed when building as part of the standard library
2323
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
2424
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
25-
// Enable extra lints:
26-
#![cfg_attr(feature = "extra_traits", warn(missing_debug_implementations))]
2725
#![warn(missing_copy_implementations, safe_packed_borrows)]
2826
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
2927
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]

src/macros.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ macro_rules! s {
112112
#[repr(C)]
113113
#[cfg_attr(
114114
feature = "extra_traits",
115-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
115+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
116+
)]
117+
#[::core::prelude::v1::derive(
118+
::core::clone::Clone,
119+
::core::marker::Copy,
120+
::core::fmt::Debug,
116121
)]
117-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
118122
#[allow(deprecated)]
119123
$(#[$attr])*
120124
pub struct $i { $($field)* }
@@ -134,17 +138,21 @@ macro_rules! s_paren {
134138
__item! {
135139
#[cfg_attr(
136140
feature = "extra_traits",
137-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
141+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
142+
)]
143+
#[::core::prelude::v1::derive(
144+
::core::clone::Clone,
145+
::core::marker::Copy,
146+
::core::fmt::Debug,
138147
)]
139-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
140148
$(#[$attr])*
141149
pub struct $i ( $($field)* );
142150
}
143151
)*);
144152
}
145153

146-
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug`
147-
/// with `extra_traits` since that can always be derived.
154+
/// Implement `Clone`, `Copy`, and `Debug` since those can be derived, but exclude `PartialEq`,
155+
/// `Eq`, and `Hash`.
148156
///
149157
/// Most items will prefer to use [`s`].
150158
macro_rules! s_no_extra_traits {
@@ -163,7 +171,6 @@ macro_rules! s_no_extra_traits {
163171
pub union $i { $($field)* }
164172
}
165173

166-
#[cfg(feature = "extra_traits")]
167174
impl ::core::fmt::Debug for $i {
168175
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
169176
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
@@ -174,8 +181,11 @@ macro_rules! s_no_extra_traits {
174181
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
175182
__item! {
176183
#[repr(C)]
177-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
178-
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
184+
#[::core::prelude::v1::derive(
185+
::core::clone::Clone,
186+
::core::marker::Copy,
187+
::core::fmt::Debug,
188+
)]
179189
$(#[$attr])*
180190
pub struct $i { $($field)* }
181191
}

src/solid/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ pub const SIGUSR1: c_int = 30;
395395
pub const SIGUSR2: c_int = 31;
396396
pub const SIGPWR: c_int = 32;
397397

398-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
398+
#[derive(Debug)]
399399
pub enum FILE {}
400400
impl Copy for FILE {}
401401
impl Clone for FILE {
402402
fn clone(&self) -> FILE {
403403
*self
404404
}
405405
}
406-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
406+
#[derive(Debug)]
407407
pub enum fpos_t {}
408408
impl Copy for fpos_t {}
409409
impl Clone for fpos_t {

src/unix/aix/powerpc64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::prelude::*;
33

44
// Define lock_data_instrumented as an empty enum
55
missing! {
6-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
6+
#[derive(Debug)]
77
pub enum lock_data_instrumented {}
88
}
99

src/unix/bsd/apple/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub type copyfile_callback_t = Option<
175175
pub type attrgroup_t = u32;
176176
pub type vol_capabilities_set_t = [u32; 4];
177177

178-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
178+
#[derive(Debug)]
179179
pub enum timezone {}
180180
impl Copy for timezone {}
181181
impl Clone for timezone {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub type vm_map_entry_t = *mut vm_map_entry;
4545

4646
pub type pmap = __c_anonymous_pmap;
4747

48-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
48+
#[derive(Debug)]
4949
pub enum sem {}
5050
impl Copy for sem {}
5151
impl Clone for sem {

src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::off_t;
22
use crate::prelude::*;
33

44
#[repr(C)]
5-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
5+
#[derive(Debug)]
6+
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
67
pub struct stat {
78
pub st_dev: crate::dev_t,
89
pub st_ino: crate::ino_t,

src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::off_t;
22
use crate::prelude::*;
33

44
#[repr(C)]
5-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
5+
#[derive(Debug)]
6+
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
67
pub struct stat {
78
pub st_dev: crate::dev_t,
89
pub st_ino: crate::ino_t,

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cfg_if! {
5959

6060
// link.h
6161

62-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
62+
#[derive(Debug)]
6363
pub enum timezone {}
6464
impl Copy for timezone {}
6565
impl Clone for timezone {

0 commit comments

Comments
 (0)