From 39ca2e622ce5d7c4985a32a769dbaf1b15ea6570 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Sun, 9 Jul 2017 14:33:11 -0500 Subject: [PATCH 1/4] 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. --- CHANGELOG.md | 6 ++++++ README.md | 13 +++---------- src/datetime.rs | 8 ++++++++ src/lib.rs | 4 +++- src/naive/datetime.rs | 8 ++++++++ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b87012..21af1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/). There were/are numerous minor versions before 1.0 due to the language changes. Versions with only mechnical changes will be omitted from the following list. +## 0.4.next + +* More strongly deprecate RustcSerialize: remove it from documentation unless + the feature is enabled, issue a deprecation warning if the rustc-serialize + feature is enabled (@quodlibetor) + ## 0.4.1 ### Bug Fixes diff --git a/README.md b/README.md index 1ce65f9..25e0300 100644 --- a/README.md +++ b/README.md @@ -46,21 +46,14 @@ Put this in your `Cargo.toml`: chrono = "0.4" ``` -Or, if you want [Serde](https://github.com/serde-rs/serde) or -[rustc-serialize](https://github.com/rust-lang-nursery/rustc-serialize) support, -include the features like this: +Or, if you want [Serde](https://github.com/serde-rs/serde) include the feature +like this: ```toml [dependencies] -chrono = { version = "0.4", features = ["serde", "rustc-serialize"] } +chrono = { version = "0.4", features = ["serde"] } ``` -> Note that Chrono's support for rustc-serialize is now considered deprecated. -Starting from 0.4.0 there is no further guarantee that -the features available in Serde will be also available to rustc-serialize, -and the support can be removed in any future major version. -**Rustc-serialize users are strongly recommended to migrate to Serde.** - Then put this in your crate root: ```rust diff --git a/src/datetime.rs b/src/datetime.rs index ec5e85a..3e12eb3 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -695,7 +695,9 @@ pub mod rustc_serialize { } } + #[allow(deprecated)] impl Decodable for TsSeconds { + #[allow(deprecated)] fn decode(d: &mut D) -> Result, D::Error> { from(FixedOffset::east(0).timestamp_opt(d.read_i64()?, 0), d) .map(TsSeconds) @@ -717,13 +719,16 @@ pub mod rustc_serialize { #[derive(Debug)] pub struct TsSeconds(DateTime); + #[allow(deprecated)] impl From> for DateTime { /// Pull the inner DateTime out + #[allow(deprecated)] fn from(obj: TsSeconds) -> DateTime { obj.0 } } + #[allow(deprecated)] impl Deref for TsSeconds { type Target = DateTime; @@ -732,6 +737,7 @@ pub mod rustc_serialize { } } + #[allow(deprecated)] impl Decodable for TsSeconds { fn decode(d: &mut D) -> Result, D::Error> { from(Utc.timestamp_opt(d.read_i64()?, 0), d) @@ -748,7 +754,9 @@ pub mod rustc_serialize { } } + #[allow(deprecated)] impl Decodable for TsSeconds { + #[allow(deprecated)] fn decode(d: &mut D) -> Result, D::Error> { from(Utc.timestamp_opt(d.read_i64()?, 0), d) .map(|dt| TsSeconds(dt.with_timezone(&Local))) diff --git a/src/lib.rs b/src/lib.rs index 6aad9ea..c10dcc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -411,7 +411,8 @@ pub use oldtime::Duration; #[doc(no_inline)] pub use naive::{NaiveDate, IsoWeek, NaiveTime, NaiveDateTime}; pub use date::{Date, MIN_DATE, MAX_DATE}; pub use datetime::{DateTime, SecondsFormat}; -#[cfg(feature = "rustc-serialize")] pub use datetime::rustc_serialize::TsSeconds; +#[cfg(feature = "rustc-serialize")] +pub use datetime::rustc_serialize::TsSeconds; pub use format::{ParseError, ParseResult}; pub use round::SubsecRound; @@ -451,6 +452,7 @@ pub mod naive { pub use self::time::NaiveTime; pub use self::datetime::NaiveDateTime; #[cfg(feature = "rustc-serialize")] + #[allow(deprecated)] pub use self::datetime::rustc_serialize::TsSeconds; diff --git a/src/naive/datetime.rs b/src/naive/datetime.rs index b1212bf..b5d1ce5 100644 --- a/src/naive/datetime.rs +++ b/src/naive/datetime.rs @@ -1503,24 +1503,32 @@ pub mod rustc_serialize { /// A `DateTime` that can be deserialized from a seconds-based timestamp #[derive(Debug)] + #[deprecated(since = "1.4.2", + note = "RustcSerialize will be removed before chrono 1.0, use Serde instead")] pub struct TsSeconds(NaiveDateTime); + #[allow(deprecated)] impl From for NaiveDateTime { /// Pull the internal NaiveDateTime out + #[allow(deprecated)] fn from(obj: TsSeconds) -> NaiveDateTime { obj.0 } } + #[allow(deprecated)] impl Deref for TsSeconds { type Target = NaiveDateTime; + #[allow(deprecated)] fn deref(&self) -> &Self::Target { &self.0 } } + #[allow(deprecated)] impl Decodable for TsSeconds { + #[allow(deprecated)] fn decode(d: &mut D) -> Result { Ok(TsSeconds( NaiveDateTime::from_timestamp_opt(d.read_i64()?, 0) From 3fb0b614e8968aa5e9c51980c25de250d89a0574 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sun, 1 Apr 2018 12:40:14 +0200 Subject: [PATCH 2/4] Revert "Allow a false-positive clippy lint" The issue has been fixed with the latest clippy release and we don't have to `allow` anymore. This reverts commit 7f990144ccb81c93354c8112f566d4c065c6b49e. --- src/format/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index de13d2c..fc1e902 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -269,8 +269,6 @@ macro_rules! fix { ($x:ident) => (Item::Fixed(Fixed::$x)) } #[derive(Debug, Clone, PartialEq, Eq, Copy)] pub struct ParseError(ParseErrorKind); -// clippy false positive https://github.com/rust-lang-nursery/rust-clippy/issues/2475 -#[cfg_attr(feature = "cargo-clippy", allow(empty_line_after_outer_attr))] #[derive(Debug, Clone, PartialEq, Eq, Copy)] enum ParseErrorKind { /// Given field is out of permitted range. From 21d302f0d2618d647c470a55b5eb25ae3bb354b9 Mon Sep 17 00:00:00 2001 From: skierpage Date: Sun, 1 Apr 2018 17:02:32 -0700 Subject: [PATCH 3/4] Update version number to 0.4.1 cargo.toml and crates.io are at 0.4.1. I don't know if you want to update the docs link and sample `Cargo.toml` lines. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ce65f9..7a4d168 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[Chrono][docsrs] 0.4.0 +[Chrono][docsrs] 0.4.1 ====================== [![Chrono on Travis CI][travis-image]][travis] From ba1b88ecbc6b2414e0098c6f90060abbd80cd4d5 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Sun, 1 Apr 2018 20:08:47 -0400 Subject: [PATCH 4/4] Remove version number from README --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7a4d168..cfff143 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[Chrono][docsrs] 0.4.1 -====================== +[Chrono][docsrs]: Date and Time for Rust +======================================== [![Chrono on Travis CI][travis-image]][travis] [![Chrono on Appveyor][appveyor-image]][appveyor] @@ -12,9 +12,8 @@ [appveyor]: https://ci.appveyor.com/project/chronotope/chrono [cratesio-image]: https://img.shields.io/crates/v/chrono.svg [cratesio]: https://crates.io/crates/chrono -[docsrs-image]: https://docs.rs/chrono/badge.svg?version=0.4.0 -[docsrs]: https://docs.rs/chrono/0.4.0/ - +[docsrs-image]: https://docs.rs/chrono/badge.svg +[docsrs]: https://docs.rs/chrono Date and time handling for Rust. It aims to be a feature-complete superset of