Skip to content

Always implement Debug #4624

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ pub type rlim_t = c_ulonglong;

// FIXME(fuchsia): why are these uninhabited types? that seems... wrong?
// Presumably these should be `()` or an `extern type` (when that stabilizes).
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum DIR {}
impl Copy for DIR {}
impl Clone for DIR {
Expand All @@ -97,7 +97,7 @@ impl Clone for DIR {
}
}

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

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum FILE {}
impl Copy for FILE {}
impl Clone for FILE {
fn clone(&self) -> FILE {
*self
}
}
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
impl Copy for fpos_t {}
impl Clone for fpos_t {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// Attributes needed when building as part of the standard library
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
// Enable extra lints:
#![cfg_attr(feature = "extra_traits", warn(missing_debug_implementations))]
#![warn(missing_copy_implementations, safe_packed_borrows)]
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
Expand Down
41 changes: 28 additions & 13 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ macro_rules! prelude {
mod prelude {
// Exports from `core`
#[allow(unused_imports)]
pub(crate) use ::core::clone::Clone;
pub(crate) use core::clone::Clone;
#[allow(unused_imports)]
pub(crate) use ::core::marker::{Copy, Send, Sync};
pub(crate) use core::fmt::Debug;
#[allow(unused_imports)]
pub(crate) use ::core::option::Option;
pub(crate) use core::marker::{Copy, Send, Sync};
#[allow(unused_imports)]
pub(crate) use ::core::{fmt, hash, iter, mem};
pub(crate) use core::option::Option;
#[allow(unused_imports)]
pub(crate) use core::prelude::v1::derive;
#[allow(unused_imports)]
pub(crate) use core::{fmt, hash, iter, mem};

#[allow(unused_imports)]
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};

Expand Down Expand Up @@ -112,9 +117,13 @@ macro_rules! s {
#[repr(C)]
#[cfg_attr(
feature = "extra_traits",
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
::core::prelude::v1::derive(Eq, Hash, PartialEq)
)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
#[allow(deprecated)]
$(#[$attr])*
pub struct $i { $($field)* }
Expand All @@ -134,17 +143,21 @@ macro_rules! s_paren {
__item! {
#[cfg_attr(
feature = "extra_traits",
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
::core::prelude::v1::derive(Eq, Hash, PartialEq)
)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
$(#[$attr])*
pub struct $i ( $($field)* );
}
)*);
}

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

#[cfg(feature = "extra_traits")]
impl ::core::fmt::Debug for $i {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
Expand All @@ -174,8 +186,11 @@ macro_rules! s_no_extra_traits {
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
$(#[$attr])*
pub struct $i { $($field)* }
}
Expand Down
4 changes: 2 additions & 2 deletions src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ pub const SIGUSR1: c_int = 30;
pub const SIGUSR2: c_int = 31;
pub const SIGPWR: c_int = 32;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum FILE {}
impl Copy for FILE {}
impl Clone for FILE {
fn clone(&self) -> FILE {
*self
}
}
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos_t {}
impl Copy for fpos_t {}
impl Clone for fpos_t {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/aix/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::*;

// Define lock_data_instrumented as an empty enum
missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum lock_data_instrumented {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub type copyfile_callback_t = Option<
pub type attrgroup_t = u32;
pub type vol_capabilities_set_t = [u32; 4];

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub type vm_map_entry_t = *mut vm_map_entry;

pub type pmap = __c_anonymous_pmap;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum sem {}
impl Copy for sem {}
impl Clone for sem {
Expand Down
3 changes: 2 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::off_t;
use crate::prelude::*;

#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Debug)]
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
Expand Down
3 changes: 2 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::off_t;
use crate::prelude::*;

#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Debug)]
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cfg_if! {

// link.h

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/bsd/netbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub type id_t = u32;
pub type sem_t = *mut sem;
pub type key_t = c_long;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum sem {}
impl Copy for sem {}
impl Clone for sem {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type nlink_t = c_ushort;
pub type suseconds_t = c_long;
pub type useconds_t = c_ulong;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub type nfds_t = c_uint;

pub type sem_t = *mut sem;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum sem {}
impl Copy for sem {}
impl Clone for sem {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type posix_spawn_file_actions_t = *mut c_void;

pub type StringList = _stringlist;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/hurd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub type nl_item = c_int;

pub type iconv_t = *mut c_void;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos64_t {} // FIXME(hurd): fill this out with a struct
impl Copy for fpos64_t {}
impl Clone for fpos64_t {
Expand All @@ -234,7 +234,7 @@ impl Clone for fpos64_t {
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub type statfs64 = crate::statfs;
pub type statvfs64 = crate::statvfs;
pub type dirent64 = crate::dirent;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos64_t {} // FIXME(emscripten): fill this out with a struct
impl Copy for fpos64_t {}
impl Clone for fpos64_t {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub type eventfd_t = u64;
cfg_if! {
if #[cfg(not(target_env = "gnu"))] {
missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos64_t {} // FIXME(linux): fill this out with a struct
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub type key_t = c_int;
pub type id_t = c_uint;

missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
}

Expand Down
6 changes: 3 additions & 3 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cfg_if! {
}

missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum DIR {}
}
pub type locale_t = *mut c_void;
Expand Down Expand Up @@ -568,14 +568,14 @@ cfg_if! {
cfg_if! {
if #[cfg(not(all(target_os = "linux", target_env = "gnu")))] {
missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum fpos_t {} // FIXME(unix): fill this out with a struct
}
}
}

missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum FILE {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/unix/nto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub type sem_t = sync_t;

pub type nl_item = c_int;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub type pid_t = usize;
pub type uid_t = u32;
pub type gid_t = u32;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/solarish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub type lgrp_view_t = c_uint;
pub type posix_spawnattr_t = *mut c_void;
pub type posix_spawn_file_actions_t = *mut c_void;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
Expand All @@ -64,7 +64,7 @@ impl Clone for timezone {
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Debug)]
pub enum ucred_t {}
impl Copy for ucred_t {}
impl Clone for ucred_t {
Expand Down
Loading
Loading