From a42c5b22cd6b4cec62f7eb0fe834fb53a085ebd9 Mon Sep 17 00:00:00 2001 From: Andrii Radyk Date: Tue, 17 Dec 2019 09:42:32 +0100 Subject: [PATCH 1/2] remove deprecated Error::description --- src/format/mod.rs | 30 ++++++++++-------------------- src/oldtime.rs | 14 ++------------ 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 83405d3..10264e2 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -318,32 +318,22 @@ enum ParseErrorKind { /// Same to `Result`. pub type ParseResult = Result; -impl ParseError { - fn description(&self) -> &str { +impl fmt::Display for ParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { - ParseErrorKind::OutOfRange => "input is out of range", - ParseErrorKind::Impossible => "no possible date and time matching input", - ParseErrorKind::NotEnough => "input is not enough for unique date and time", - ParseErrorKind::Invalid => "input contains invalid characters", - ParseErrorKind::TooShort => "premature end of input", - ParseErrorKind::TooLong => "trailing input", - ParseErrorKind::BadFormat => "bad or unsupported format string", + ParseErrorKind::OutOfRange => write!(f, "input is out of range"), + ParseErrorKind::Impossible => write!(f, "no possible date and time matching input"), + ParseErrorKind::NotEnough => write!(f, "input is not enough for unique date and time"), + ParseErrorKind::Invalid => write!(f, "input contains invalid characters"), + ParseErrorKind::TooShort => write!(f, "premature end of input"), + ParseErrorKind::TooLong => write!(f, "trailing input"), + ParseErrorKind::BadFormat => write!(f, "bad or unsupported format string"), } } } -impl fmt::Display for ParseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.description().fmt(f) - } -} - #[cfg(any(feature = "std", test))] -impl Error for ParseError { - fn description(&self) -> &str { - self.description() - } -} +impl Error for ParseError {} // to be used in this module and submodules const OUT_OF_RANGE: ParseError = ParseError(ParseErrorKind::OutOfRange); diff --git a/src/oldtime.rs b/src/oldtime.rs index bed8136..741a4cd 100644 --- a/src/oldtime.rs +++ b/src/oldtime.rs @@ -393,24 +393,14 @@ impl fmt::Display for Duration { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct OutOfRangeError(()); -impl OutOfRangeError { - fn description(&self) -> &str { - "Source duration value is out of range for the target type" - } -} - impl fmt::Display for OutOfRangeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.description()) + write!(f, "Source duration value is out of range for the target type") } } #[cfg(any(feature = "std", test))] -impl Error for OutOfRangeError { - fn description(&self) -> &str { - self.description() - } -} +impl Error for OutOfRangeError {} // Copied from libnum #[inline] From 977ad603913d2b96f4137e6add0a3a6aefb98d91 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Mon, 23 Dec 2019 12:38:09 -0500 Subject: [PATCH 2/2] allow_deprecated on stub Error::description for rust 1.13 --- src/format/mod.rs | 7 ++++++- src/oldtime.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 10264e2..1099f18 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -333,7 +333,12 @@ impl fmt::Display for ParseError { } #[cfg(any(feature = "std", test))] -impl Error for ParseError {} +impl Error for ParseError { + #[allow(deprecated)] + fn description(&self) -> &str { + "parser error, see to_string() for details" + } +} // to be used in this module and submodules const OUT_OF_RANGE: ParseError = ParseError(ParseErrorKind::OutOfRange); diff --git a/src/oldtime.rs b/src/oldtime.rs index 741a4cd..1cc8a15 100644 --- a/src/oldtime.rs +++ b/src/oldtime.rs @@ -400,7 +400,12 @@ impl fmt::Display for OutOfRangeError { } #[cfg(any(feature = "std", test))] -impl Error for OutOfRangeError {} +impl Error for OutOfRangeError { + #[allow(deprecated)] + fn description(&self) -> &str { + "out of range error" + } +} // Copied from libnum #[inline]