Skip to content

Commit

Permalink
Remove unnessary Copy and Send impls
Browse files Browse the repository at this point in the history
Fuchsia is doing an audit of chrono 0.4.34, and we noticed an unncessary
unsafe of `Send` for `DateTime`. While it's valid since `Tz::Offset` is
`Send`, and `NaiveDateTime` only has `u32` fields, there's a potential
hazard if `NaiveDateTime` ever grows unsendable fields (unlikely as that
is).

This (and the `Copy` impl) were added 9 years ago to fix #25, which
stemmed from early versions of associate traits not working properly
with auto-traits. This has since been fixed, and is no longer necessary
with the MSRV 1.61.0.
  • Loading branch information
erickt authored and djc committed Mar 7, 2024
1 parent 3114597 commit e79fe21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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(Clone)]
#[derive(Copy, Clone)]
#[cfg_attr(
any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
Expand Down Expand Up @@ -1386,10 +1386,6 @@ impl<Tz: TimeZone> Timelike for DateTime<Tz> {
}
}

// we need them as automatic impls cannot handle associated types
impl<Tz: TimeZone> Copy for DateTime<Tz> where <Tz as TimeZone>::Offset: Copy {}
unsafe impl<Tz: TimeZone> Send for DateTime<Tz> where <Tz as TimeZone>::Offset: Send {}

impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<DateTime<Tz2>> for DateTime<Tz> {
fn eq(&self, other: &DateTime<Tz2>) -> bool {
self.datetime == other.datetime
Expand Down
9 changes: 9 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,3 +1866,12 @@ fn nano_roundrip() {
assert_eq!(nanos, nanos2);
}
}

#[test]
fn test_datetime_utc_is_copy_and_send() {
fn is_copy<T: Copy>(_: T) {}
fn is_send<T: Send>(_: T) {}

is_copy(DateTime::<Utc>::MIN_UTC);
is_send(DateTime::<Utc>::MIN_UTC);
}

0 comments on commit e79fe21

Please sign in to comment.