diff --git a/CITATION.cff b/CITATION.cff index 0e44adfac8..96cbf16cdd 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,8 +3,8 @@ cff-version: 1.2.0 message: Please cite this crate using these information. # Version information. -date-released: 2024-03-27 -version: 0.4.37 +date-released: 2024-04-15 +version: 0.4.38 # Project information. abstract: Date and time library for Rust diff --git a/Cargo.toml b/Cargo.toml index 4a555d21ac..e84c7eb8a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chrono" -version = "0.4.37" +version = "0.4.38" description = "Date and time library for Rust" homepage = "https://github.com/chronotope/chrono" documentation = "https://docs.rs/chrono/" diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 366bbe6ad7..28cc64ab79 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -46,7 +46,7 @@ mod tests; /// There are some constructors implemented here (the `from_*` methods), but /// the general-purpose constructors are all via the methods on the /// [`TimeZone`](./offset/trait.TimeZone.html) implementations. -#[derive(Copy, Clone)] +#[derive(Clone)] #[cfg_attr( any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"), derive(Archive, Deserialize, Serialize), @@ -1408,6 +1408,15 @@ impl Timelike for DateTime { } } +// We don't store a field with the `Tz` type, so it doesn't need to influence whether `DateTime` can +// be `Copy`. Implement it manually if the two types we do have are `Copy`. +impl Copy for DateTime +where + ::Offset: Copy, + NaiveDateTime: Copy, +{ +} + impl PartialEq> for DateTime { fn eq(&self, other: &DateTime) -> bool { self.datetime == other.datetime diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 126e1d34d1..c890863d8b 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -1,8 +1,8 @@ use super::DateTime; use crate::naive::{NaiveDate, NaiveTime}; -use crate::offset::{FixedOffset, TimeZone, Utc}; #[cfg(feature = "clock")] -use crate::offset::{Local, Offset}; +use crate::offset::Local; +use crate::offset::{FixedOffset, Offset, TimeZone, Utc}; use crate::{Datelike, Days, MappedLocalTime, Months, NaiveDateTime, TimeDelta, Timelike, Weekday}; #[derive(Clone)] @@ -1318,9 +1318,44 @@ fn test_datetime_format_with_local() { #[test] fn test_datetime_is_send_and_copy() { + #[derive(Clone)] + struct Tz { + _not_send: *const i32, + } + impl TimeZone for Tz { + type Offset = Off; + + fn from_offset(_: &Self::Offset) -> Self { + unimplemented!() + } + fn offset_from_local_date(&self, _: &NaiveDate) -> crate::MappedLocalTime { + unimplemented!() + } + fn offset_from_local_datetime( + &self, + _: &NaiveDateTime, + ) -> crate::MappedLocalTime { + unimplemented!() + } + fn offset_from_utc_date(&self, _: &NaiveDate) -> Self::Offset { + unimplemented!() + } + fn offset_from_utc_datetime(&self, _: &NaiveDateTime) -> Self::Offset { + unimplemented!() + } + } + + #[derive(Copy, Clone, Debug)] + struct Off(()); + impl Offset for Off { + fn fix(&self) -> FixedOffset { + unimplemented!() + } + } + fn _assert_send_copy() {} - // UTC is known to be `Send + Copy`. - _assert_send_copy::>(); + // `DateTime` is `Send + Copy` if the offset is. + _assert_send_copy::>(); } #[test]