Skip to content

Commit dfb7b0f

Browse files
authored
Merge pull request #1249 from joshtriplett/simplify-cfg-within-function
Avoid using #[cfg] on multiple individual function arguments
2 parents 39f35da + 6fc27ee commit dfb7b0f

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

gix-index/src/fs.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ impl Metadata {
5454
pub fn modified(&self) -> Option<SystemTime> {
5555
#[cfg(not(windows))]
5656
{
57+
#[cfg(not(target_os = "aix"))]
58+
let seconds = self.0.st_mtime;
59+
#[cfg(target_os = "aix")]
60+
let seconds = self.0.st_mtim.tv_sec;
61+
62+
#[cfg(not(any(target_os = "netbsd", target_os = "aix")))]
63+
let nanoseconds = self.0.st_mtime_nsec;
64+
#[cfg(target_os = "netbsd")]
65+
let nanoseconds = self.0.st_mtimensec;
66+
#[cfg(target_os = "aix")]
67+
let nanoseconds = self.0.st_mtim.tv_nsec;
68+
5769
Some(system_time_from_secs_nanos(
58-
#[cfg(not(target_os = "aix"))]
59-
self.0.st_mtime.try_into().ok()?,
60-
#[cfg(target_os = "aix")]
61-
self.0.st_mtim.tv_sec.try_into().ok()?,
62-
#[cfg(not(any(target_os = "netbsd", target_os = "aix")))]
63-
self.0.st_mtime_nsec.try_into().ok()?,
64-
#[cfg(target_os = "netbsd")]
65-
self.0.st_mtimensec.try_into().ok()?,
66-
#[cfg(target_os = "aix")]
67-
self.0.st_mtim.tv_nsec.try_into().ok()?,
70+
seconds.try_into().ok()?,
71+
nanoseconds.try_into().ok()?,
6872
))
6973
}
7074
#[cfg(windows)]
@@ -78,17 +82,21 @@ impl Metadata {
7882
pub fn created(&self) -> Option<SystemTime> {
7983
#[cfg(not(windows))]
8084
{
85+
#[cfg(not(target_os = "aix"))]
86+
let seconds = self.0.st_ctime;
87+
#[cfg(target_os = "aix")]
88+
let seconds = self.0.st_ctim.tv_sec;
89+
90+
#[cfg(not(any(target_os = "netbsd", target_os = "aix")))]
91+
let nanoseconds = self.0.st_ctime_nsec;
92+
#[cfg(target_os = "netbsd")]
93+
let nanoseconds = self.0.st_ctimensec;
94+
#[cfg(target_os = "aix")]
95+
let nanoseconds = self.0.st_ctim.tv_nsec;
96+
8197
Some(system_time_from_secs_nanos(
82-
#[cfg(not(target_os = "aix"))]
83-
self.0.st_ctime.try_into().ok()?,
84-
#[cfg(target_os = "aix")]
85-
self.0.st_ctim.tv_sec.try_into().ok()?,
86-
#[cfg(not(any(target_os = "netbsd", target_os = "aix")))]
87-
self.0.st_ctime_nsec.try_into().ok()?,
88-
#[cfg(target_os = "netbsd")]
89-
self.0.st_ctimensec.try_into().ok()?,
90-
#[cfg(target_os = "aix")]
91-
self.0.st_ctim.tv_nsec.try_into().ok()?,
98+
seconds.try_into().ok()?,
99+
nanoseconds.try_into().ok()?,
92100
))
93101
}
94102
#[cfg(windows)]

0 commit comments

Comments
 (0)