Skip to content

Commit 18304d1

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 18304d1

File tree

24 files changed

+71
-56
lines changed

24 files changed

+71
-56
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: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ macro_rules! prelude {
7070
mod prelude {
7171
// Exports from `core`
7272
#[allow(unused_imports)]
73-
pub(crate) use ::core::clone::Clone;
73+
pub(crate) use core::clone::Clone;
7474
#[allow(unused_imports)]
75-
pub(crate) use ::core::marker::{Copy, Send, Sync};
75+
pub(crate) use core::fmt::Debug;
7676
#[allow(unused_imports)]
77-
pub(crate) use ::core::option::Option;
77+
pub(crate) use core::marker::{Copy, Send, Sync};
7878
#[allow(unused_imports)]
79-
pub(crate) use ::core::{fmt, hash, iter, mem};
79+
pub(crate) use core::option::Option;
80+
#[allow(unused_imports)]
81+
pub(crate) use core::prelude::v1::derive;
82+
#[allow(unused_imports)]
83+
pub(crate) use core::{fmt, hash, iter, mem};
84+
8085
#[allow(unused_imports)]
8186
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8287

@@ -112,9 +117,13 @@ macro_rules! s {
112117
#[repr(C)]
113118
#[cfg_attr(
114119
feature = "extra_traits",
115-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
120+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
121+
)]
122+
#[::core::prelude::v1::derive(
123+
::core::clone::Clone,
124+
::core::marker::Copy,
125+
::core::fmt::Debug,
116126
)]
117-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
118127
#[allow(deprecated)]
119128
$(#[$attr])*
120129
pub struct $i { $($field)* }
@@ -134,17 +143,21 @@ macro_rules! s_paren {
134143
__item! {
135144
#[cfg_attr(
136145
feature = "extra_traits",
137-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
146+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
147+
)]
148+
#[::core::prelude::v1::derive(
149+
::core::clone::Clone,
150+
::core::marker::Copy,
151+
::core::fmt::Debug,
138152
)]
139-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
140153
$(#[$attr])*
141154
pub struct $i ( $($field)* );
142155
}
143156
)*);
144157
}
145158

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.
159+
/// Implement `Clone`, `Copy`, and `Debug` since those can be derived, but exclude `PartialEq`,
160+
/// `Eq`, and `Hash`.
148161
///
149162
/// Most items will prefer to use [`s`].
150163
macro_rules! s_no_extra_traits {
@@ -163,7 +176,6 @@ macro_rules! s_no_extra_traits {
163176
pub union $i { $($field)* }
164177
}
165178

166-
#[cfg(feature = "extra_traits")]
167179
impl ::core::fmt::Debug for $i {
168180
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
169181
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
@@ -174,8 +186,11 @@ macro_rules! s_no_extra_traits {
174186
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
175187
__item! {
176188
#[repr(C)]
177-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
178-
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
189+
#[::core::prelude::v1::derive(
190+
::core::clone::Clone,
191+
::core::marker::Copy,
192+
::core::fmt::Debug,
193+
)]
179194
$(#[$attr])*
180195
pub struct $i { $($field)* }
181196
}

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)