From 43e8b5131606fb36424689de856dde28d484a9a9 Mon Sep 17 00:00:00 2001 From: Geert-Jan Zwiers Date: Tue, 3 Jan 2023 21:04:02 +0100 Subject: [PATCH] chore: resolve clippy errors in windows build (#17215) --- runtime/ops/os/sys_info.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/runtime/ops/os/sys_info.rs b/runtime/ops/os/sys_info.rs index 06807a8ea7..366864f46d 100644 --- a/runtime/ops/os/sys_info.rs +++ b/runtime/ops/os/sys_info.rs @@ -302,17 +302,19 @@ pub fn mem_info() -> Option { } pub fn os_uptime() -> u64 { - let mut uptime: u64 = 0; + let uptime: u64; #[cfg(target_os = "linux")] { let mut info = std::mem::MaybeUninit::uninit(); // SAFETY: `info` is a valid pointer to a `libc::sysinfo` struct. let res = unsafe { libc::sysinfo(info.as_mut_ptr()) }; - if res == 0 { + uptime = if res == 0 { // SAFETY: `sysinfo` initializes the struct. let info = unsafe { info.assume_init() }; - uptime = info.uptime as u64; + info.uptime as u64 + } else { + 0 } } @@ -341,8 +343,8 @@ pub fn os_uptime() -> u64 { 0, ) }; - if res == 0 { - uptime = SystemTime::now() + uptime = if res == 0 { + SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .map(|d| { (d - Duration::new( @@ -351,15 +353,18 @@ pub fn os_uptime() -> u64 { )) .as_secs() }) - .unwrap_or_default(); + .unwrap_or_default() + } else { + 0 } } #[cfg(target_family = "windows")] + // SAFETY: windows API usage unsafe { // Windows is the only one that returns `uptime` in milisecond precision, // so we need to get the seconds out of it to be in sync with other envs. - uptime = winapi::um::sysinfoapi::GetTickCount64() as u64 / 1000; + uptime = winapi::um::sysinfoapi::GetTickCount64() / 1000; } uptime