Skip to content

chore: use auto-derived copy/clone impls #4417

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
37 changes: 7 additions & 30 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,16 @@ 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(Clone, Copy)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum DIR {}
impl Copy for DIR {}
impl Clone for DIR {
fn clone(&self) -> DIR {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum fpos64_t {} // FIXME(fuchsia): fill this out with a struct
impl Copy for fpos64_t {}
impl Clone for fpos64_t {
fn clone(&self) -> fpos64_t {
*self
}
}

// PUB_STRUCT

Expand Down Expand Up @@ -3541,21 +3527,12 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
extern "C" {}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum FILE {}
impl Copy for FILE {}
impl Clone for FILE {
fn clone(&self) -> FILE {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
impl Copy for fpos_t {}
impl Clone for fpos_t {
fn clone(&self) -> fpos_t {
*self
}
}

extern "C" {
pub fn isalnum(c: c_int) -> c_int;
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ macro_rules! prelude {
#[allow(unused_imports)]
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};

// Commonly used types defined in this crate
Expand Down
15 changes: 3 additions & 12 deletions src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,12 @@ pub const SIGUSR2: c_int = 31;
pub const SIGPWR: c_int = 32;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum FILE {}
impl Copy for FILE {}
impl Clone for FILE {
fn clone(&self) -> FILE {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum fpos_t {}
impl Copy for fpos_t {}
impl Clone for fpos_t {
fn clone(&self) -> fpos_t {
*self
}
}

extern "C" {
// ctype.h
Expand Down
28 changes: 4 additions & 24 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,11 @@ pub type attrgroup_t = u32;
pub type vol_capabilities_set_t = [u32; 4];

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum qos_class_t {
QOS_CLASS_USER_INTERACTIVE = 0x21,
Expand All @@ -194,14 +190,9 @@ pub enum qos_class_t {
QOS_CLASS_BACKGROUND = 0x09,
QOS_CLASS_UNSPECIFIED = 0x00,
}
impl Copy for qos_class_t {}
impl Clone for qos_class_t {
fn clone(&self) -> qos_class_t {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum sysdir_search_path_directory_t {
SYSDIR_DIRECTORY_APPLICATION = 1,
Expand Down Expand Up @@ -229,14 +220,9 @@ pub enum sysdir_search_path_directory_t {
SYSDIR_DIRECTORY_ALL_APPLICATIONS = 100,
SYSDIR_DIRECTORY_ALL_LIBRARIES = 101,
}
impl Copy for sysdir_search_path_directory_t {}
impl Clone for sysdir_search_path_directory_t {
fn clone(&self) -> sysdir_search_path_directory_t {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum sysdir_search_path_domain_mask_t {
SYSDIR_DOMAIN_MASK_USER = (1 << 0),
Expand All @@ -245,12 +231,6 @@ pub enum sysdir_search_path_domain_mask_t {
SYSDIR_DOMAIN_MASK_SYSTEM = (1 << 3),
SYSDIR_DOMAIN_MASK_ALL = 0x0ffff,
}
impl Copy for sysdir_search_path_domain_mask_t {}
impl Clone for sysdir_search_path_domain_mask_t {
fn clone(&self) -> sysdir_search_path_domain_mask_t {
*self
}
}

s! {
pub struct ip_mreq {
Expand Down
7 changes: 1 addition & 6 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ pub type vm_map_entry_t = *mut vm_map_entry;
pub type pmap = __c_anonymous_pmap;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum sem {}
impl Copy for sem {}
impl Clone for sem {
fn clone(&self) -> sem {
*self
}
}

e! {
#[repr(u32)]
Expand Down
8 changes: 1 addition & 7 deletions src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::prelude::*;

#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Clone, Copy)]
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
Expand All @@ -27,10 +28,3 @@ pub struct stat {
pub st_birthtime_nsec: c_long,
__unused: [u8; 8],
}

impl Copy for crate::stat {}
impl Clone for crate::stat {
fn clone(&self) -> crate::stat {
*self
}
}
8 changes: 1 addition & 7 deletions src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::prelude::*;

#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Clone, Copy)]
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
Expand All @@ -26,10 +27,3 @@ pub struct stat {
pub st_birthtime: crate::time_t,
pub st_birthtime_nsec: c_long,
}

impl Copy for crate::stat {}
impl Clone for crate::stat {
fn clone(&self) -> crate::stat {
*self
}
}
64 changes: 9 additions & 55 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,17 @@ pub type sctp_assoc_t = u32;
pub type eventfd_t = u64;

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_support_flags {
DEVSTAT_ALL_SUPPORTED = 0x00,
DEVSTAT_NO_BLOCKSIZE = 0x01,
DEVSTAT_NO_ORDERED_TAGS = 0x02,
DEVSTAT_BS_UNAVAILABLE = 0x04,
}
impl Copy for devstat_support_flags {}
impl Clone for devstat_support_flags {
fn clone(&self) -> devstat_support_flags {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_trans_flags {
DEVSTAT_NO_DATA = 0x00,
Expand All @@ -74,44 +70,28 @@ pub enum devstat_trans_flags {
DEVSTAT_FREE = 0x03,
}

impl Copy for devstat_trans_flags {}
impl Clone for devstat_trans_flags {
fn clone(&self) -> devstat_trans_flags {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_tag_type {
DEVSTAT_TAG_SIMPLE = 0x00,
DEVSTAT_TAG_HEAD = 0x01,
DEVSTAT_TAG_ORDERED = 0x02,
DEVSTAT_TAG_NONE = 0x03,
}
impl Copy for devstat_tag_type {}
impl Clone for devstat_tag_type {
fn clone(&self) -> devstat_tag_type {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_match_flags {
DEVSTAT_MATCH_NONE = 0x00,
DEVSTAT_MATCH_TYPE = 0x01,
DEVSTAT_MATCH_IF = 0x02,
DEVSTAT_MATCH_PASS = 0x04,
}
impl Copy for devstat_match_flags {}
impl Clone for devstat_match_flags {
fn clone(&self) -> devstat_match_flags {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_priority {
DEVSTAT_PRIORITY_MIN = 0x000,
Expand All @@ -125,14 +105,9 @@ pub enum devstat_priority {
DEVSTAT_PRIORITY_ARRAY = 0x120,
DEVSTAT_PRIORITY_MAX = 0xfff,
}
impl Copy for devstat_priority {}
impl Clone for devstat_priority {
fn clone(&self) -> devstat_priority {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_type_flags {
DEVSTAT_TYPE_DIRECT = 0x000,
Expand All @@ -157,14 +132,9 @@ pub enum devstat_type_flags {
DEVSTAT_TYPE_IF_MASK = 0x0f0,
DEVSTAT_TYPE_PASS = 0x100,
}
impl Copy for devstat_type_flags {}
impl Clone for devstat_type_flags {
fn clone(&self) -> devstat_type_flags {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_metric {
DSM_NONE,
Expand Down Expand Up @@ -214,27 +184,16 @@ pub enum devstat_metric {
DSM_TOTAL_BUSY_TIME,
DSM_MAX,
}
impl Copy for devstat_metric {}
impl Clone for devstat_metric {
fn clone(&self) -> devstat_metric {
*self
}
}

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum devstat_select_mode {
DS_SELECT_ADD,
DS_SELECT_ONLY,
DS_SELECT_REMOVE,
DS_SELECT_ADDONLY,
}
impl Copy for devstat_select_mode {}
impl Clone for devstat_select_mode {
fn clone(&self) -> devstat_select_mode {
*self
}
}

s! {
pub struct __c_anonymous_sigev_thread {
Expand Down Expand Up @@ -2600,6 +2559,7 @@ cfg_if! {
}

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum dot3Vendors {
dot3VendorAMD = 1,
Expand All @@ -2609,12 +2569,6 @@ pub enum dot3Vendors {
dot3VendorDigital = 6,
dot3VendorWesternDigital = 7,
}
impl Copy for dot3Vendors {}
impl Clone for dot3Vendors {
fn clone(&self) -> dot3Vendors {
*self
}
}

// aio.h
pub const LIO_VECTORED: c_int = 4;
Expand Down
7 changes: 1 addition & 6 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@ cfg_if! {
// link.h

#[cfg_attr(feature = "extra_traits", derive(Debug))]
#[derive(Clone, Copy)]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut c_void {
Expand Down
Loading
Loading