Skip to content

Commit d568cff

Browse files
committed
Remove unnessary Copy and Send impls
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.
1 parent 3114597 commit d568cff

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/datetime/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod tests;
4949
/// There are some constructors implemented here (the `from_*` methods), but
5050
/// the general-purpose constructors are all via the methods on the
5151
/// [`TimeZone`](./offset/trait.TimeZone.html) implementations.
52-
#[derive(Clone)]
52+
#[derive(Copy, Clone)]
5353
#[cfg_attr(
5454
any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
5555
derive(Archive, Deserialize, Serialize),
@@ -1386,10 +1386,6 @@ impl<Tz: TimeZone> Timelike for DateTime<Tz> {
13861386
}
13871387
}
13881388

1389-
// we need them as automatic impls cannot handle associated types
1390-
impl<Tz: TimeZone> Copy for DateTime<Tz> where <Tz as TimeZone>::Offset: Copy {}
1391-
unsafe impl<Tz: TimeZone> Send for DateTime<Tz> where <Tz as TimeZone>::Offset: Send {}
1392-
13931389
impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<DateTime<Tz2>> for DateTime<Tz> {
13941390
fn eq(&self, other: &DateTime<Tz2>) -> bool {
13951391
self.datetime == other.datetime
@@ -2048,3 +2044,12 @@ fn test_decodable_json_timestamps<FUtc, FFixed, FLocal, E>(
20482044
Utc.with_ymd_and_hms(1969, 12, 31, 23, 59, 59).unwrap()
20492045
);
20502046
}
2047+
2048+
#[test]
2049+
fn test_datetime_utc_is_copy_and_send() {
2050+
fn is_copy<T: Copy>(_: T) {}
2051+
fn is_send<T: Send>(_: T) {}
2052+
2053+
is_copy(DateTime::<Utc>::MIN_UTC);
2054+
is_send(DateTime::<Utc>::MIN_UTC);
2055+
}

0 commit comments

Comments
 (0)