From 74d02933a56a6a142cbf21d466d09f4a09b3abc7 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 29 Jan 2020 15:15:58 -0800 Subject: [PATCH] Fix warnings about deprecated Error::description --- src/codec/error.rs | 59 +++++++++++------------------- src/error.rs | 12 +----- tests/h2-tests/tests/codec_read.rs | 3 +- 3 files changed, 24 insertions(+), 50 deletions(-) diff --git a/src/codec/error.rs b/src/codec/error.rs index c6d4e95..2c6b296 100644 --- a/src/codec/error.rs +++ b/src/codec/error.rs @@ -73,43 +73,33 @@ impl From for RecvError { } } -impl error::Error for RecvError { - fn description(&self) -> &str { - use self::RecvError::*; - - match *self { - Connection(ref reason) => reason.description(), - Stream { ref reason, .. } => reason.description(), - Io(ref e) => e.description(), - } - } -} +impl error::Error for RecvError {} impl fmt::Display for RecvError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - use std::error::Error; - write!(fmt, "{}", self.description()) + use self::RecvError::*; + + match *self { + Connection(ref reason) => reason.fmt(fmt), + Stream { ref reason, .. } => reason.fmt(fmt), + Io(ref e) => e.fmt(fmt), + } } } // ===== impl SendError ===== -impl error::Error for SendError { - fn description(&self) -> &str { - use self::SendError::*; - - match *self { - User(ref e) => e.description(), - Connection(ref reason) => reason.description(), - Io(ref e) => e.description(), - } - } -} +impl error::Error for SendError {} impl fmt::Display for SendError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - use std::error::Error; - write!(fmt, "{}", self.description()) + use self::SendError::*; + + match *self { + User(ref e) => e.fmt(fmt), + Connection(ref reason) => reason.fmt(fmt), + Io(ref e) => e.fmt(fmt), + } } } @@ -127,11 +117,13 @@ impl From for SendError { // ===== impl UserError ===== -impl error::Error for UserError { - fn description(&self) -> &str { +impl error::Error for UserError {} + +impl fmt::Display for UserError { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { use self::UserError::*; - match *self { + fmt.write_str(match *self { InactiveStreamId => "inactive stream", UnexpectedFrameType => "unexpected frame type", PayloadTooBig => "payload too big", @@ -144,13 +136,6 @@ impl error::Error for UserError { PollResetAfterSendResponse => "poll_reset after send_response is illegal", SendPingWhilePending => "send_ping before received previous pong", SendSettingsWhilePending => "sending SETTINGS before received previous ACK", - } - } -} - -impl fmt::Display for UserError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - use std::error::Error; - write!(fmt, "{}", self.description()) + }) } } diff --git a/src/error.rs b/src/error.rs index c1a13e7..372bac2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -132,14 +132,4 @@ impl fmt::Display for Error { } } -impl error::Error for Error { - fn description(&self) -> &str { - use self::Kind::*; - - match self.kind { - Io(ref e) => error::Error::description(e), - Proto(ref reason) => reason.description(), - User(ref user) => user.description(), - } - } -} +impl error::Error for Error {} diff --git a/tests/h2-tests/tests/codec_read.rs b/tests/h2-tests/tests/codec_read.rs index 8d96e0d..6ebe54d 100644 --- a/tests/h2-tests/tests/codec_read.rs +++ b/tests/h2-tests/tests/codec_read.rs @@ -1,6 +1,5 @@ use futures::future::join; use h2_support::prelude::*; -use std::error::Error; #[tokio::test] async fn read_none() { @@ -209,7 +208,7 @@ async fn update_max_frame_len_at_rest() { assert_eq!(codec.max_recv_frame_size(), 16_384); assert_eq!( - codec.next().await.unwrap().unwrap_err().description(), + codec.next().await.unwrap().unwrap_err().to_string(), "frame with invalid size" ); }