Skip to content

Commit 4a46fbe

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 (backport <#4624>) (cherry picked from commit a6e7563) [ needed to apply in a few more places, including the e! macro definition - Trevor ]
1 parent 28f612d commit 4a46fbe

File tree

25 files changed

+97
-72
lines changed

25 files changed

+97
-72
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
@@ -25,8 +25,6 @@
2525
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
2626
// DIFF(1.0): The thread local references that raise this lint were removed in 1.0
2727
#![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))]
28-
// Enable extra lints:
29-
#![cfg_attr(feature = "extra_traits", warn(missing_debug_implementations))]
3028
#![warn(missing_copy_implementations, safe_packed_borrows)]
3129
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
3230
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]

src/macros.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ macro_rules! prelude {
7272
mod prelude {
7373
// Exports from `core`
7474
#[allow(unused_imports)]
75-
pub(crate) use ::core::clone::Clone;
75+
pub(crate) use core::clone::Clone;
7676
#[allow(unused_imports)]
77-
pub(crate) use ::core::default::Default;
77+
pub(crate) use core::default::Default;
7878
#[allow(unused_imports)]
79-
pub(crate) use ::core::marker::{Copy, Send, Sync};
79+
pub(crate) use core::marker::{Copy, Send, Sync};
8080
#[allow(unused_imports)]
81-
pub(crate) use ::core::option::Option;
81+
pub(crate) use core::option::Option;
8282
#[allow(unused_imports)]
83-
pub(crate) use ::core::prelude::v1::derive;
83+
pub(crate) use core::prelude::v1::derive;
8484
#[allow(unused_imports)]
85-
pub(crate) use ::core::{fmt, hash, iter, mem, ptr};
85+
pub(crate) use core::{fmt, hash, iter, mem, ptr};
86+
87+
#[allow(unused_imports)]
88+
pub(crate) use fmt::Debug;
8689
#[allow(unused_imports)]
8790
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8891

@@ -120,9 +123,13 @@ macro_rules! s {
120123
#[repr(C)]
121124
#[cfg_attr(
122125
feature = "extra_traits",
123-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
126+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
127+
)]
128+
#[::core::prelude::v1::derive(
129+
::core::clone::Clone,
130+
::core::marker::Copy,
131+
::core::fmt::Debug,
124132
)]
125-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
126133
#[allow(deprecated)]
127134
$(#[$attr])*
128135
pub struct $i { $($field)* }
@@ -142,17 +149,21 @@ macro_rules! s_paren {
142149
__item! {
143150
#[cfg_attr(
144151
feature = "extra_traits",
145-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
152+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
153+
)]
154+
#[::core::prelude::v1::derive(
155+
::core::clone::Clone,
156+
::core::marker::Copy,
157+
::core::fmt::Debug,
146158
)]
147-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
148159
$(#[$attr])*
149160
pub struct $i ( $($field)* );
150161
}
151162
)*);
152163
}
153164

154-
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug`
155-
/// with `extra_traits` since that can always be derived.
165+
/// Implement `Clone`, `Copy`, and `Debug` since those can be derived, but exclude `PartialEq`,
166+
/// `Eq`, and `Hash`.
156167
///
157168
/// Most items will prefer to use [`s`].
158169
macro_rules! s_no_extra_traits {
@@ -171,7 +182,6 @@ macro_rules! s_no_extra_traits {
171182
pub union $i { $($field)* }
172183
}
173184

174-
#[cfg(feature = "extra_traits")]
175185
impl ::core::fmt::Debug for $i {
176186
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
177187
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
@@ -182,8 +192,11 @@ macro_rules! s_no_extra_traits {
182192
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
183193
__item! {
184194
#[repr(C)]
185-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
186-
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
195+
#[::core::prelude::v1::derive(
196+
::core::clone::Clone,
197+
::core::marker::Copy,
198+
::core::fmt::Debug,
199+
)]
187200
$(#[$attr])*
188201
pub struct $i { $($field)* }
189202
}
@@ -214,9 +227,13 @@ macro_rules! e {
214227
__item! {
215228
#[cfg_attr(
216229
feature = "extra_traits",
217-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
230+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
231+
)]
232+
#[::core::prelude::v1::derive(
233+
::core::clone::Clone,
234+
::core::marker::Copy,
235+
::core::fmt::Debug,
218236
)]
219-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
220237
$(#[$attr])*
221238
pub enum $i { $($field)* }
222239
}

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ deprecated_mach! {
179179
pub type mach_timebase_info_data_t = mach_timebase_info;
180180
}
181181

182-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
182+
#[derive(Debug)]
183183
pub enum timezone {}
184184
impl Copy for timezone {}
185185
impl Clone for timezone {
@@ -188,7 +188,7 @@ impl Clone for timezone {
188188
}
189189
}
190190

191-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
191+
#[derive(Debug)]
192192
#[repr(u32)]
193193
pub enum qos_class_t {
194194
QOS_CLASS_USER_INTERACTIVE = 0x21,
@@ -205,7 +205,7 @@ impl Clone for qos_class_t {
205205
}
206206
}
207207

208-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
208+
#[derive(Debug)]
209209
#[repr(u32)]
210210
pub enum sysdir_search_path_directory_t {
211211
SYSDIR_DIRECTORY_APPLICATION = 1,
@@ -240,7 +240,7 @@ impl Clone for sysdir_search_path_directory_t {
240240
}
241241
}
242242

243-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
243+
#[derive(Debug)]
244244
#[repr(u32)]
245245
pub enum sysdir_search_path_domain_mask_t {
246246
SYSDIR_DOMAIN_MASK_USER = (1 << 0),

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/freebsd/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ pub type sctp_assoc_t = u32;
5353

5454
pub type eventfd_t = u64;
5555

56-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
56+
#[derive(Debug)]
57+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
5758
#[repr(u32)]
5859
pub enum devstat_support_flags {
5960
DEVSTAT_ALL_SUPPORTED = 0x00,
@@ -68,7 +69,8 @@ impl Clone for devstat_support_flags {
6869
}
6970
}
7071

71-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
72+
#[derive(Debug)]
73+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
7274
#[repr(u32)]
7375
pub enum devstat_trans_flags {
7476
DEVSTAT_NO_DATA = 0x00,
@@ -84,7 +86,8 @@ impl Clone for devstat_trans_flags {
8486
}
8587
}
8688

87-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
89+
#[derive(Debug)]
90+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
8891
#[repr(u32)]
8992
pub enum devstat_tag_type {
9093
DEVSTAT_TAG_SIMPLE = 0x00,
@@ -99,7 +102,8 @@ impl Clone for devstat_tag_type {
99102
}
100103
}
101104

102-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
105+
#[derive(Debug)]
106+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
103107
#[repr(u32)]
104108
pub enum devstat_match_flags {
105109
DEVSTAT_MATCH_NONE = 0x00,
@@ -114,7 +118,8 @@ impl Clone for devstat_match_flags {
114118
}
115119
}
116120

117-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
121+
#[derive(Debug)]
122+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
118123
#[repr(u32)]
119124
pub enum devstat_priority {
120125
DEVSTAT_PRIORITY_MIN = 0x000,
@@ -135,7 +140,8 @@ impl Clone for devstat_priority {
135140
}
136141
}
137142

138-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
143+
#[derive(Debug)]
144+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
139145
#[repr(u32)]
140146
pub enum devstat_type_flags {
141147
DEVSTAT_TYPE_DIRECT = 0x000,
@@ -167,7 +173,8 @@ impl Clone for devstat_type_flags {
167173
}
168174
}
169175

170-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
176+
#[derive(Debug)]
177+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
171178
#[repr(u32)]
172179
pub enum devstat_metric {
173180
DSM_NONE,
@@ -224,7 +231,8 @@ impl Clone for devstat_metric {
224231
}
225232
}
226233

227-
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
234+
#[derive(Debug)]
235+
#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))]
228236
#[repr(u32)]
229237
pub enum devstat_select_mode {
230238
DS_SELECT_ADD,
@@ -2387,7 +2395,7 @@ cfg_if! {
23872395
}
23882396
}
23892397

2390-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
2398+
#[derive(Debug)]
23912399
#[repr(u32)]
23922400
pub enum dot3Vendors {
23932401
dot3VendorAMD = 1,

0 commit comments

Comments
 (0)