From f3625b5022c62632c959c1928ee3e03e7e6bdccd Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sun, 11 Sep 2022 17:40:15 +0200 Subject: [PATCH] Fix feature issues --- src/datetime/mod.rs | 1 + src/error.rs | 16 +++++++--------- src/naive/date.rs | 1 + src/offset/utc.rs | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index a38d48d414..c9fcaaa2fa 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -11,6 +11,7 @@ use alloc::string::{String, ToString}; #[cfg(any(feature = "alloc", feature = "std", test))] use core::borrow::Borrow; use core::cmp::Ordering; +#[cfg(feature = "clock")] use core::convert::TryFrom; use core::ops::{Add, AddAssign, Sub, SubAssign}; use core::{fmt, hash, str}; diff --git a/src/error.rs b/src/error.rs index 9a64ff0558..01588b3aa8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,4 @@ use core::fmt; -#[cfg(windows)] -use std::io; /// Internal representation of the chrono error. #[derive(Debug)] @@ -12,10 +10,10 @@ pub(crate) enum ChronoErrorKind { AmbiguousDate, #[cfg(unix)] MissingDate, - #[cfg(windows)] + #[cfg(all(windows, feature = "clock"))] SystemTimeBeforeEpoch, - #[cfg(windows)] - SystemError(io::Error), + #[cfg(all(windows, feature = "clock"))] + SystemError(std::io::Error), } /// The error raised for an invalid date time. @@ -42,9 +40,9 @@ impl fmt::Display for ChronoError { ChronoErrorKind::AmbiguousDate => write!(f, "tried to operate over ambiguous date"), #[cfg(unix)] ChronoErrorKind::MissingDate => write!(f, "missing date"), - #[cfg(windows)] + #[cfg(all(windows, feature = "clock"))] ChronoErrorKind::SystemTimeBeforeEpoch => write!(f, "system time before Unix epoch"), - #[cfg(windows)] + #[cfg(all(windows, feature = "clock"))] ChronoErrorKind::SystemError(error) => write!(f, "system error: {error}"), } } @@ -61,7 +59,7 @@ impl From for ChronoError { impl std::error::Error for ChronoError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self.kind { - #[cfg(windows)] + #[cfg(all(windows, feature = "clock"))] ChronoErrorKind::SystemError(error) => Some(error), _ => None, } @@ -80,7 +78,7 @@ impl PartialEq for ChronoError { impl PartialEq for ChronoErrorKind { fn eq(&self, other: &Self) -> bool { match (self, other) { - #[cfg(windows)] + #[cfg(all(windows, feature = "clock"))] (Self::SystemError(l0), Self::SystemError(r0)) => l0.kind() == r0.kind(), _ => core::mem::discriminant(self) == core::mem::discriminant(other), } diff --git a/src/naive/date.rs b/src/naive/date.rs index 983cb51d3d..2e8529fdb8 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -747,6 +747,7 @@ impl NaiveDate { } /// Makes a new `NaiveDateTime` with the time set to midnight. + #[cfg(feature = "clock")] pub(crate) fn and_midnight(&self) -> NaiveDateTime { self.and_time(NaiveTime::midnight()) } diff --git a/src/offset/utc.rs b/src/offset/utc.rs index 6199b5e683..c4b1468fc0 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -19,8 +19,9 @@ use rkyv::{Archive, Deserialize, Serialize}; use super::{FixedOffset, FixedTimeZone, Offset, TimeZone}; use crate::naive::{NaiveDate, NaiveDateTime}; +use crate::{ChronoError, LocalResult}; #[cfg(feature = "clock")] -use crate::{ChronoError, Date, DateTime, LocalResult}; +use crate::{Date, DateTime}; /// The UTC time zone. This is the most efficient time zone when you don't need the local time. /// It is also used as an offset (which is also a dummy type).