Skip to content

Commit 39ca2e6

Browse files
committed
Deprecated warnings in cargo output for rustc-serialize feature
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s of `Encodable`/`Decodable` for the various items have no effect whatsoever, so we need to place it on some type that chrono actually uses internally. The only *type* that I can find that only exists for rustc-serialize only is the `TsSeconds` struct. So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds` to emit deprecation warnings, both in our builds and for packages that specify Chrono as a dependency with the `rustc-serialize` feature active. This means that the current commit will cause a `warning: use of deprecated item: RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear in `cargo build` output. Unfortunately I don't think that it's possible for downstream crates to disable the warning the warning in any way other than actually switching to Serde or using an older chrono. That's the reason for all the `#[allow(deprecated)]` through the code, it means that the warning appears almost exactly once, instead of dozens of times.
1 parent ee52f2f commit 39ca2e6

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/).
88
There were/are numerous minor versions before 1.0 due to the language changes.
99
Versions with only mechnical changes will be omitted from the following list.
1010

11+
## 0.4.next
12+
13+
* More strongly deprecate RustcSerialize: remove it from documentation unless
14+
the feature is enabled, issue a deprecation warning if the rustc-serialize
15+
feature is enabled (@quodlibetor)
16+
1117
## 0.4.1
1218

1319
### Bug Fixes

README.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,14 @@ Put this in your `Cargo.toml`:
4646
chrono = "0.4"
4747
```
4848

49-
Or, if you want [Serde](https://github.com/serde-rs/serde) or
50-
[rustc-serialize](https://github.com/rust-lang-nursery/rustc-serialize) support,
51-
include the features like this:
49+
Or, if you want [Serde](https://github.com/serde-rs/serde) include the feature
50+
like this:
5251

5352
```toml
5453
[dependencies]
55-
chrono = { version = "0.4", features = ["serde", "rustc-serialize"] }
54+
chrono = { version = "0.4", features = ["serde"] }
5655
```
5756

58-
> Note that Chrono's support for rustc-serialize is now considered deprecated.
59-
Starting from 0.4.0 there is no further guarantee that
60-
the features available in Serde will be also available to rustc-serialize,
61-
and the support can be removed in any future major version.
62-
**Rustc-serialize users are strongly recommended to migrate to Serde.**
63-
6457
Then put this in your crate root:
6558

6659
```rust

src/datetime.rs

+8
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ pub mod rustc_serialize {
695695
}
696696
}
697697

698+
#[allow(deprecated)]
698699
impl Decodable for TsSeconds<FixedOffset> {
700+
#[allow(deprecated)]
699701
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<FixedOffset>, D::Error> {
700702
from(FixedOffset::east(0).timestamp_opt(d.read_i64()?, 0), d)
701703
.map(TsSeconds)
@@ -717,13 +719,16 @@ pub mod rustc_serialize {
717719
#[derive(Debug)]
718720
pub struct TsSeconds<Tz: TimeZone>(DateTime<Tz>);
719721

722+
#[allow(deprecated)]
720723
impl<Tz: TimeZone> From<TsSeconds<Tz>> for DateTime<Tz> {
721724
/// Pull the inner DateTime<Tz> out
725+
#[allow(deprecated)]
722726
fn from(obj: TsSeconds<Tz>) -> DateTime<Tz> {
723727
obj.0
724728
}
725729
}
726730

731+
#[allow(deprecated)]
727732
impl<Tz: TimeZone> Deref for TsSeconds<Tz> {
728733
type Target = DateTime<Tz>;
729734

@@ -732,6 +737,7 @@ pub mod rustc_serialize {
732737
}
733738
}
734739

740+
#[allow(deprecated)]
735741
impl Decodable for TsSeconds<Utc> {
736742
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<Utc>, D::Error> {
737743
from(Utc.timestamp_opt(d.read_i64()?, 0), d)
@@ -748,7 +754,9 @@ pub mod rustc_serialize {
748754
}
749755
}
750756

757+
#[allow(deprecated)]
751758
impl Decodable for TsSeconds<Local> {
759+
#[allow(deprecated)]
752760
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<Local>, D::Error> {
753761
from(Utc.timestamp_opt(d.read_i64()?, 0), d)
754762
.map(|dt| TsSeconds(dt.with_timezone(&Local)))

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ pub use oldtime::Duration;
411411
#[doc(no_inline)] pub use naive::{NaiveDate, IsoWeek, NaiveTime, NaiveDateTime};
412412
pub use date::{Date, MIN_DATE, MAX_DATE};
413413
pub use datetime::{DateTime, SecondsFormat};
414-
#[cfg(feature = "rustc-serialize")] pub use datetime::rustc_serialize::TsSeconds;
414+
#[cfg(feature = "rustc-serialize")]
415+
pub use datetime::rustc_serialize::TsSeconds;
415416
pub use format::{ParseError, ParseResult};
416417
pub use round::SubsecRound;
417418

@@ -451,6 +452,7 @@ pub mod naive {
451452
pub use self::time::NaiveTime;
452453
pub use self::datetime::NaiveDateTime;
453454
#[cfg(feature = "rustc-serialize")]
455+
#[allow(deprecated)]
454456
pub use self::datetime::rustc_serialize::TsSeconds;
455457

456458

src/naive/datetime.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1503,24 +1503,32 @@ pub mod rustc_serialize {
15031503

15041504
/// A `DateTime` that can be deserialized from a seconds-based timestamp
15051505
#[derive(Debug)]
1506+
#[deprecated(since = "1.4.2",
1507+
note = "RustcSerialize will be removed before chrono 1.0, use Serde instead")]
15061508
pub struct TsSeconds(NaiveDateTime);
15071509

1510+
#[allow(deprecated)]
15081511
impl From<TsSeconds> for NaiveDateTime {
15091512
/// Pull the internal NaiveDateTime out
1513+
#[allow(deprecated)]
15101514
fn from(obj: TsSeconds) -> NaiveDateTime {
15111515
obj.0
15121516
}
15131517
}
15141518

1519+
#[allow(deprecated)]
15151520
impl Deref for TsSeconds {
15161521
type Target = NaiveDateTime;
15171522

1523+
#[allow(deprecated)]
15181524
fn deref(&self) -> &Self::Target {
15191525
&self.0
15201526
}
15211527
}
15221528

1529+
#[allow(deprecated)]
15231530
impl Decodable for TsSeconds {
1531+
#[allow(deprecated)]
15241532
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds, D::Error> {
15251533
Ok(TsSeconds(
15261534
NaiveDateTime::from_timestamp_opt(d.read_i64()?, 0)

0 commit comments

Comments
 (0)