Skip to content

Commit 0824652

Browse files
committed
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]
1 parent 86fbdbf commit 0824652

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/libcore/result.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
use self::Result::{Ok, Err};
230230

231231
use clone::Clone;
232-
use fmt::Display;
232+
use fmt::Debug;
233233
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
234234
use ops::{FnMut, FnOnce};
235235
use option::Option::{self, None, Some};
@@ -714,7 +714,7 @@ impl<T, E> Result<T, E> {
714714
}
715715

716716
#[stable]
717-
impl<T, E: Display> Result<T, E> {
717+
impl<T, E: Debug> Result<T, E> {
718718
/// Unwraps a result, yielding the content of an `Ok`.
719719
///
720720
/// # Panics
@@ -739,13 +739,13 @@ impl<T, E: Display> Result<T, E> {
739739
match self {
740740
Ok(t) => t,
741741
Err(e) =>
742-
panic!("called `Result::unwrap()` on an `Err` value: {}", e)
742+
panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
743743
}
744744
}
745745
}
746746

747747
#[stable]
748-
impl<T: Display, E> Result<T, E> {
748+
impl<T: Debug, E> Result<T, E> {
749749
/// Unwraps a result, yielding the content of an `Err`.
750750
///
751751
/// # Panics
@@ -769,7 +769,7 @@ impl<T: Display, E> Result<T, E> {
769769
pub fn unwrap_err(self) -> E {
770770
match self {
771771
Ok(t) =>
772-
panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
772+
panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t),
773773
Err(e) => e
774774
}
775775
}

src/libstd/sync/mpsc/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<T> !Sync for SyncSender<T> {}
382382
/// A `send` operation can only fail if the receiving end of a channel is
383383
/// disconnected, implying that the data could never be received. The error
384384
/// contains the data being sent as a payload so it can be recovered.
385-
#[derive(PartialEq, Eq, Show)]
385+
#[derive(PartialEq, Eq)]
386386
#[stable]
387387
pub struct SendError<T>(pub T);
388388

@@ -412,7 +412,7 @@ pub enum TryRecvError {
412412

413413
/// This enumeration is the list of the possible error outcomes for the
414414
/// `SyncSender::try_send` method.
415-
#[derive(PartialEq, Clone, Show)]
415+
#[derive(PartialEq, Clone)]
416416
#[stable]
417417
pub enum TrySendError<T> {
418418
/// The data could not be sent on the channel because it would require that
@@ -961,13 +961,30 @@ impl<T: Send> Drop for Receiver<T> {
961961
}
962962
}
963963

964+
#[stable]
965+
impl<T> fmt::Debug for SendError<T> {
966+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
967+
"SendError(..)".fmt(f)
968+
}
969+
}
970+
964971
#[stable]
965972
impl<T> fmt::Display for SendError<T> {
966973
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
967974
"sending on a closed channel".fmt(f)
968975
}
969976
}
970977

978+
#[stable]
979+
impl<T> fmt::Debug for TrySendError<T> {
980+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
981+
match *self {
982+
TrySendError::Full(..) => "Full(..)".fmt(f),
983+
TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f),
984+
}
985+
}
986+
}
987+
971988
#[stable]
972989
impl<T> fmt::Display for TrySendError<T> {
973990
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

src/libstd/sync/poison.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ pub struct Guard {
5353
/// is held. The precise semantics for when a lock is poisoned is documented on
5454
/// each lock, but once a lock is poisoned then all future acquisitions will
5555
/// return this error.
56-
#[derive(Show)]
5756
#[stable]
5857
pub struct PoisonError<T> {
5958
guard: T,
6059
}
6160

6261
/// An enumeration of possible errors which can occur while calling the
6362
/// `try_lock` method.
64-
#[derive(Show)]
6563
#[stable]
6664
pub enum TryLockError<T> {
6765
/// The lock could not be acquired because another task failed while holding
@@ -92,6 +90,13 @@ pub type LockResult<Guard> = Result<Guard, PoisonError<Guard>>;
9290
#[stable]
9391
pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;
9492

93+
#[stable]
94+
impl<T> fmt::Debug for PoisonError<T> {
95+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96+
"PoisonError { inner: .. }".fmt(f)
97+
}
98+
}
99+
95100
#[stable]
96101
impl<T> fmt::Display for PoisonError<T> {
97102
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -133,6 +138,16 @@ impl<T> FromError<PoisonError<T>> for TryLockError<T> {
133138
}
134139
}
135140

141+
#[stable]
142+
impl<T> fmt::Debug for TryLockError<T> {
143+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
144+
match *self {
145+
TryLockError::Poisoned(..) => "Poisoned(..)".fmt(f),
146+
TryLockError::WouldBlock => "WouldBlock".fmt(f)
147+
}
148+
}
149+
}
150+
136151
#[stable]
137152
impl<T> fmt::Display for TryLockError<T> {
138153
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

0 commit comments

Comments
 (0)