Skip to content

Commit 5c936c0

Browse files
committed
cleanup: Also use s_no_extra_traits! for private structs
(backport <#4808>) (cherry picked from commit b4cb730)
1 parent 1f9b825 commit 5c936c0

File tree

7 files changed

+154
-233
lines changed

7 files changed

+154
-233
lines changed
Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
use crate::off_t;
22
use crate::prelude::*;
33

4-
#[repr(C)]
5-
#[derive(Debug)]
6-
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
7-
pub struct stat {
8-
pub st_dev: crate::dev_t,
9-
pub st_ino: crate::ino_t,
10-
pub st_mode: crate::mode_t,
11-
pub st_nlink: crate::nlink_t,
12-
pub st_uid: crate::uid_t,
13-
pub st_gid: crate::gid_t,
14-
pub st_rdev: crate::dev_t,
15-
pub st_atime: crate::time_t,
16-
pub st_atime_nsec: c_long,
17-
pub st_mtime: crate::time_t,
18-
pub st_mtime_nsec: c_long,
19-
pub st_ctime: crate::time_t,
20-
pub st_ctime_nsec: c_long,
21-
pub st_size: off_t,
22-
pub st_blocks: crate::blkcnt_t,
23-
pub st_blksize: crate::blksize_t,
24-
pub st_flags: crate::fflags_t,
25-
pub st_gen: u32,
26-
pub st_lspare: i32,
27-
pub st_birthtime: crate::time_t,
28-
pub st_birthtime_nsec: c_long,
29-
__unused: [u8; 8],
30-
}
31-
32-
impl Copy for crate::stat {}
33-
impl Clone for crate::stat {
34-
fn clone(&self) -> crate::stat {
35-
*self
4+
s! {
5+
pub struct stat {
6+
pub st_dev: crate::dev_t,
7+
pub st_ino: crate::ino_t,
8+
pub st_mode: crate::mode_t,
9+
pub st_nlink: crate::nlink_t,
10+
pub st_uid: crate::uid_t,
11+
pub st_gid: crate::gid_t,
12+
pub st_rdev: crate::dev_t,
13+
pub st_atime: crate::time_t,
14+
pub st_atime_nsec: c_long,
15+
pub st_mtime: crate::time_t,
16+
pub st_mtime_nsec: c_long,
17+
pub st_ctime: crate::time_t,
18+
pub st_ctime_nsec: c_long,
19+
pub st_size: off_t,
20+
pub st_blocks: crate::blkcnt_t,
21+
pub st_blksize: crate::blksize_t,
22+
pub st_flags: crate::fflags_t,
23+
pub st_gen: u32,
24+
pub st_lspare: i32,
25+
pub st_birthtime: crate::time_t,
26+
pub st_birthtime_nsec: c_long,
27+
__unused: [u8; 8],
3628
}
3729
}
Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
use crate::off_t;
22
use crate::prelude::*;
33

4-
#[repr(C)]
5-
#[derive(Debug)]
6-
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
7-
pub struct stat {
8-
pub st_dev: crate::dev_t,
9-
pub st_ino: crate::ino_t,
10-
pub st_mode: crate::mode_t,
11-
pub st_nlink: crate::nlink_t,
12-
pub st_uid: crate::uid_t,
13-
pub st_gid: crate::gid_t,
14-
pub st_rdev: crate::dev_t,
15-
pub st_atime: crate::time_t,
16-
pub st_atime_nsec: c_long,
17-
pub st_mtime: crate::time_t,
18-
pub st_mtime_nsec: c_long,
19-
pub st_ctime: crate::time_t,
20-
pub st_ctime_nsec: c_long,
21-
pub st_size: off_t,
22-
pub st_blocks: crate::blkcnt_t,
23-
pub st_blksize: crate::blksize_t,
24-
pub st_flags: crate::fflags_t,
25-
pub st_gen: u32,
26-
pub st_lspare: i32,
27-
pub st_birthtime: crate::time_t,
28-
pub st_birthtime_nsec: c_long,
29-
}
30-
31-
impl Copy for crate::stat {}
32-
impl Clone for crate::stat {
33-
fn clone(&self) -> crate::stat {
34-
*self
4+
s! {
5+
pub struct stat {
6+
pub st_dev: crate::dev_t,
7+
pub st_ino: crate::ino_t,
8+
pub st_mode: crate::mode_t,
9+
pub st_nlink: crate::nlink_t,
10+
pub st_uid: crate::uid_t,
11+
pub st_gid: crate::gid_t,
12+
pub st_rdev: crate::dev_t,
13+
pub st_atime: crate::time_t,
14+
pub st_atime_nsec: c_long,
15+
pub st_mtime: crate::time_t,
16+
pub st_mtime_nsec: c_long,
17+
pub st_ctime: crate::time_t,
18+
pub st_ctime_nsec: c_long,
19+
pub st_size: off_t,
20+
pub st_blocks: crate::blkcnt_t,
21+
pub st_blksize: crate::blksize_t,
22+
pub st_flags: crate::fflags_t,
23+
pub st_gen: u32,
24+
pub st_lspare: i32,
25+
pub st_birthtime: crate::time_t,
26+
pub st_birthtime_nsec: c_long,
3527
}
3628
}

src/unix/linux_like/android/mod.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,29 @@ s_no_extra_traits! {
630630
pub ifc_len: c_int, /* Size of buffer. */
631631
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
632632
}
633+
634+
// Internal, for casts to access union fields
635+
struct sifields_sigchld {
636+
si_pid: crate::pid_t,
637+
si_uid: crate::uid_t,
638+
si_status: c_int,
639+
si_utime: c_long,
640+
si_stime: c_long,
641+
}
642+
643+
// Internal, for casts to access union fields
644+
union sifields {
645+
_align_pointer: *mut c_void,
646+
sigchld: sifields_sigchld,
647+
}
648+
649+
// Internal, for casts to access union fields. Note that some variants
650+
// of sifields start with a pointer, which makes the alignment of
651+
// sifields vary on 32-bit and 64-bit architectures.
652+
struct siginfo_f {
653+
_siginfo_base: [c_int; 3],
654+
sifields: sifields,
655+
}
633656
}
634657

635658
cfg_if! {
@@ -3860,38 +3883,6 @@ impl siginfo_t {
38603883
}
38613884
}
38623885

3863-
// Internal, for casts to access union fields
3864-
#[repr(C)]
3865-
struct sifields_sigchld {
3866-
si_pid: crate::pid_t,
3867-
si_uid: crate::uid_t,
3868-
si_status: c_int,
3869-
si_utime: c_long,
3870-
si_stime: c_long,
3871-
}
3872-
impl Copy for sifields_sigchld {}
3873-
impl Clone for sifields_sigchld {
3874-
fn clone(&self) -> sifields_sigchld {
3875-
*self
3876-
}
3877-
}
3878-
3879-
// Internal, for casts to access union fields
3880-
#[repr(C)]
3881-
union sifields {
3882-
_align_pointer: *mut c_void,
3883-
sigchld: sifields_sigchld,
3884-
}
3885-
3886-
// Internal, for casts to access union fields. Note that some variants
3887-
// of sifields start with a pointer, which makes the alignment of
3888-
// sifields vary on 32-bit and 64-bit architectures.
3889-
#[repr(C)]
3890-
struct siginfo_f {
3891-
_siginfo_base: [c_int; 3],
3892-
sifields: sifields,
3893-
}
3894-
38953886
impl siginfo_t {
38963887
unsafe fn sifields(&self) -> &sifields {
38973888
&(*(self as *const siginfo_t as *const siginfo_f)).sifields

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -422,36 +422,29 @@ impl siginfo_t {
422422
}
423423
}
424424

425-
// Internal, for casts to access union fields
426-
#[repr(C)]
427-
struct sifields_sigchld {
428-
si_pid: crate::pid_t,
429-
si_uid: crate::uid_t,
430-
si_status: c_int,
431-
si_utime: c_long,
432-
si_stime: c_long,
433-
}
434-
impl Copy for sifields_sigchld {}
435-
impl Clone for sifields_sigchld {
436-
fn clone(&self) -> sifields_sigchld {
437-
*self
425+
s_no_extra_traits! {
426+
// Internal, for casts to access union fields
427+
struct sifields_sigchld {
428+
si_pid: crate::pid_t,
429+
si_uid: crate::uid_t,
430+
si_status: c_int,
431+
si_utime: c_long,
432+
si_stime: c_long,
438433
}
439-
}
440434

441-
// Internal, for casts to access union fields
442-
#[repr(C)]
443-
union sifields {
444-
_align_pointer: *mut c_void,
445-
sigchld: sifields_sigchld,
446-
}
435+
// Internal, for casts to access union fields
436+
union sifields {
437+
_align_pointer: *mut c_void,
438+
sigchld: sifields_sigchld,
439+
}
447440

448-
// Internal, for casts to access union fields. Note that some variants
449-
// of sifields start with a pointer, which makes the alignment of
450-
// sifields vary on 32-bit and 64-bit architectures.
451-
#[repr(C)]
452-
struct siginfo_f {
453-
_siginfo_base: [c_int; 3],
454-
sifields: sifields,
441+
// Internal, for casts to access union fields. Note that some variants
442+
// of sifields start with a pointer, which makes the alignment of
443+
// sifields vary on 32-bit and 64-bit architectures.
444+
struct siginfo_f {
445+
_siginfo_base: [c_int; 3],
446+
sifields: sifields,
447+
}
455448
}
456449

457450
impl siginfo_t {

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,29 @@ impl siginfo_t {
6363
}
6464
}
6565

66-
// Internal, for casts to access union fields
67-
#[repr(C)]
68-
struct sifields_sigchld {
69-
si_pid: crate::pid_t,
70-
si_uid: crate::uid_t,
71-
si_status: c_int,
72-
si_utime: c_long,
73-
si_stime: c_long,
74-
}
75-
impl Copy for sifields_sigchld {}
76-
impl Clone for sifields_sigchld {
77-
fn clone(&self) -> sifields_sigchld {
78-
*self
66+
s_no_extra_traits! {
67+
// Internal, for casts to access union fields
68+
struct sifields_sigchld {
69+
si_pid: crate::pid_t,
70+
si_uid: crate::uid_t,
71+
si_status: c_int,
72+
si_utime: c_long,
73+
si_stime: c_long,
7974
}
80-
}
8175

82-
// Internal, for casts to access union fields
83-
#[repr(C)]
84-
union sifields {
85-
_align_pointer: *mut c_void,
86-
sigchld: sifields_sigchld,
87-
}
76+
// Internal, for casts to access union fields
77+
union sifields {
78+
_align_pointer: *mut c_void,
79+
sigchld: sifields_sigchld,
80+
}
8881

89-
// Internal, for casts to access union fields. Note that some variants
90-
// of sifields start with a pointer, which makes the alignment of
91-
// sifields vary on 32-bit and 64-bit architectures.
92-
#[repr(C)]
93-
struct siginfo_f {
94-
_siginfo_base: [c_int; 3],
95-
sifields: sifields,
82+
// Internal, for casts to access union fields. Note that some variants
83+
// of sifields start with a pointer, which makes the alignment of
84+
// sifields vary on 32-bit and 64-bit architectures.
85+
struct siginfo_f {
86+
_siginfo_base: [c_int; 3],
87+
sifields: sifields,
88+
}
9689
}
9790

9891
impl siginfo_t {

src/unix/linux_like/linux/uclibc/mod.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -181,36 +181,29 @@ impl siginfo_t {
181181
}
182182
}
183183

184-
// Internal, for casts to access union fields
185-
#[repr(C)]
186-
struct sifields_sigchld {
187-
si_pid: crate::pid_t,
188-
si_uid: crate::uid_t,
189-
si_status: c_int,
190-
si_utime: c_long,
191-
si_stime: c_long,
192-
}
193-
impl Copy for sifields_sigchld {}
194-
impl Clone for sifields_sigchld {
195-
fn clone(&self) -> sifields_sigchld {
196-
*self
184+
s_no_extra_traits! {
185+
// Internal, for casts to access union fields
186+
struct sifields_sigchld {
187+
si_pid: crate::pid_t,
188+
si_uid: crate::uid_t,
189+
si_status: c_int,
190+
si_utime: c_long,
191+
si_stime: c_long,
197192
}
198-
}
199193

200-
// Internal, for casts to access union fields
201-
#[repr(C)]
202-
union sifields {
203-
_align_pointer: *mut c_void,
204-
sigchld: sifields_sigchld,
205-
}
194+
// Internal, for casts to access union fields
195+
union sifields {
196+
_align_pointer: *mut c_void,
197+
sigchld: sifields_sigchld,
198+
}
206199

207-
// Internal, for casts to access union fields. Note that some variants
208-
// of sifields start with a pointer, which makes the alignment of
209-
// sifields vary on 32-bit and 64-bit architectures.
210-
#[repr(C)]
211-
struct siginfo_f {
212-
_siginfo_base: [c_int; 3],
213-
sifields: sifields,
200+
// Internal, for casts to access union fields. Note that some variants
201+
// of sifields start with a pointer, which makes the alignment of
202+
// sifields vary on 32-bit and 64-bit architectures.
203+
struct siginfo_f {
204+
_siginfo_base: [c_int; 3],
205+
sifields: sifields,
206+
}
214207
}
215208

216209
impl siginfo_t {

0 commit comments

Comments
 (0)