From 2d1ccda2ef41808ea4e98cf13c46fd5c5526dd22 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 22 Feb 2025 09:32:38 +0100 Subject: [PATCH] style(clippy): ban direct use of `std::time::SystemTime::now` (#1043) --- clippy.toml | 3 +++ src/time.rs | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000..954823b --- /dev/null +++ b/clippy.toml @@ -0,0 +1,3 @@ +disallowed-methods = [ + { "path" = "std::time::SystemTime::now", reason = "does not work on WASM environments", replacement = "crate::time::now" } +] diff --git a/src/time.rs b/src/time.rs index 0fc47f2..7b46b57 100644 --- a/src/time.rs +++ b/src/time.rs @@ -9,10 +9,18 @@ pub(crate) fn now() -> SystemTime { SystemTime::UNIX_EPOCH + duration } + // FIXME: change to: + // #[allow( + // clippy::disallowed_methods, + // reason = "`web-time` aliases `std::time::SystemTime::now` on non-WASM platforms" + // )] + #[allow(clippy::disallowed_methods)] to_std_systemtime(web_time::SystemTime::now()) } #[cfg(not(feature = "web"))] pub(crate) fn now() -> SystemTime { + // FIXME: change to #[expect(clippy::disallowed_methods, reason = "the `web` feature is disabled")] + #[allow(clippy::disallowed_methods)] SystemTime::now() }