From 08246520c0fef902b169233e26e15cf58ef1cd8b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 23 Jan 2015 10:38:50 -0800 Subject: [PATCH] std: Relax Result::unwrap() to Debug This commit relaxes the bound on `Result::unwrap` and `Result::unwrap_err` from the `Display` trait to the `Debug` trait for generating an error message about the unwrapping operation. This commit is a breaking change and any breakage should be mitigated by ensuring that `Debug` is implemented on the relevant type. [breaking-change] --- src/libcore/result.rs | 10 +++++----- src/libstd/sync/mpsc/mod.rs | 21 +++++++++++++++++++-- src/libstd/sync/poison.rs | 19 +++++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index c3d49e24978..118f29ccfa4 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -229,7 +229,7 @@ use self::Result::{Ok, Err}; use clone::Clone; -use fmt::Display; +use fmt::Debug; use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator}; use ops::{FnMut, FnOnce}; use option::Option::{self, None, Some}; @@ -714,7 +714,7 @@ impl Result { } #[stable] -impl Result { +impl Result { /// Unwraps a result, yielding the content of an `Ok`. /// /// # Panics @@ -739,13 +739,13 @@ impl Result { match self { Ok(t) => t, Err(e) => - panic!("called `Result::unwrap()` on an `Err` value: {}", e) + panic!("called `Result::unwrap()` on an `Err` value: {:?}", e) } } } #[stable] -impl Result { +impl Result { /// Unwraps a result, yielding the content of an `Err`. /// /// # Panics @@ -769,7 +769,7 @@ impl Result { pub fn unwrap_err(self) -> E { match self { Ok(t) => - panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t), + panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t), Err(e) => e } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 062bdf346cd..893f353b1a7 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -382,7 +382,7 @@ impl !Sync for SyncSender {} /// A `send` operation can only fail if the receiving end of a channel is /// disconnected, implying that the data could never be received. The error /// contains the data being sent as a payload so it can be recovered. -#[derive(PartialEq, Eq, Show)] +#[derive(PartialEq, Eq)] #[stable] pub struct SendError(pub T); @@ -412,7 +412,7 @@ pub enum TryRecvError { /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. -#[derive(PartialEq, Clone, Show)] +#[derive(PartialEq, Clone)] #[stable] pub enum TrySendError { /// The data could not be sent on the channel because it would require that @@ -961,6 +961,13 @@ impl Drop for Receiver { } } +#[stable] +impl fmt::Debug for SendError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + "SendError(..)".fmt(f) + } +} + #[stable] impl fmt::Display for SendError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -968,6 +975,16 @@ impl fmt::Display for SendError { } } +#[stable] +impl fmt::Debug for TrySendError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + TrySendError::Full(..) => "Full(..)".fmt(f), + TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f), + } + } +} + #[stable] impl fmt::Display for TrySendError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index c97fcf7cefb..d7fcee3ae2e 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -53,7 +53,6 @@ pub struct Guard { /// is held. The precise semantics for when a lock is poisoned is documented on /// each lock, but once a lock is poisoned then all future acquisitions will /// return this error. -#[derive(Show)] #[stable] pub struct PoisonError { guard: T, @@ -61,7 +60,6 @@ pub struct PoisonError { /// An enumeration of possible errors which can occur while calling the /// `try_lock` method. -#[derive(Show)] #[stable] pub enum TryLockError { /// The lock could not be acquired because another task failed while holding @@ -92,6 +90,13 @@ pub type LockResult = Result>; #[stable] pub type TryLockResult = Result>; +#[stable] +impl fmt::Debug for PoisonError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + "PoisonError { inner: .. }".fmt(f) + } +} + #[stable] impl fmt::Display for PoisonError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -133,6 +138,16 @@ impl FromError> for TryLockError { } } +#[stable] +impl fmt::Debug for TryLockError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + TryLockError::Poisoned(..) => "Poisoned(..)".fmt(f), + TryLockError::WouldBlock => "WouldBlock".fmt(f) + } + } +} + #[stable] impl fmt::Display for TryLockError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {