Skip to content

Commit b4830f2

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 61b722e commit b4830f2

File tree

24 files changed

+71
-58
lines changed

24 files changed

+71
-58
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 {
@@ -3469,15 +3469,15 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
34693469
#[link(name = "fdio")]
34703470
extern "C" {}
34713471

3472-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3472+
#[derive(Debug)]
34733473
pub enum FILE {}
34743474
impl Copy for FILE {}
34753475
impl Clone for FILE {
34763476
fn clone(&self) -> FILE {
34773477
*self
34783478
}
34793479
}
3480-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3480+
#[derive(Debug)]
34813481
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
34823482
impl Copy for fpos_t {}
34833483
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 & 15 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::{fmt, hash, iter, mem};
8282
#[allow(unused_imports)]
83-
pub(crate) use ::core::prelude::v1::derive;
83+
pub(crate) use core::option::Option;
8484
#[allow(unused_imports)]
85-
pub(crate) use ::core::{fmt, hash, iter, mem};
85+
pub(crate) use core::prelude::v1::derive;
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
}

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)