Skip to content

Commit ee48d16

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 ee48d16

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/datetime/mod.rs

+1-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

src/datetime/tests.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1866,3 +1866,12 @@ fn nano_roundrip() {
18661866
assert_eq!(nanos, nanos2);
18671867
}
18681868
}
1869+
1870+
#[test]
1871+
fn test_datetime_utc_is_copy_and_send() {
1872+
fn is_copy<T: Copy>(_: T) {}
1873+
fn is_send<T: Send>(_: T) {}
1874+
1875+
is_copy(DateTime::<Utc>::MIN_UTC);
1876+
is_send(DateTime::<Utc>::MIN_UTC);
1877+
}

0 commit comments

Comments
 (0)