Skip to content

Commit

Permalink
Make cold unwraps take &dyn Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jul 11, 2019
1 parent 5a7e730 commit 955979a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ impl<T: fmt::Debug> Option<T> {
#[unstable(feature = "option_expect_none", reason = "newly added", issue = "0")]
pub fn expect_none(self, msg: &str) {
if let Some(val) = self {
expect_none_failed(msg, val);
expect_none_failed(msg, &val);
}
}

Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl<T: fmt::Debug> Option<T> {
#[unstable(feature = "option_unwrap_none", reason = "newly added", issue = "0")]
pub fn unwrap_none(self) {
if let Some(val) = self {
expect_none_failed("called `Option::unwrap_none()` on a `Some` value", val);
expect_none_failed("called `Option::unwrap_none()` on a `Some` value", &val);
}
}
}
Expand Down Expand Up @@ -1153,7 +1153,7 @@ fn expect_failed(msg: &str) -> ! {
// This is a separate function to reduce the code size of .expect_none() itself.
#[inline(never)]
#[cold]
fn expect_none_failed<T: fmt::Debug>(msg: &str, value: T) -> ! {
fn expect_none_failed(msg: &str, value: &dyn fmt::Debug) -> ! {
panic!("{}: {:?}", msg, value)
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
pub fn unwrap(self) -> T {
match self {
Ok(t) => t,
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", e),
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", &e),
}
}

Expand All @@ -876,7 +876,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
pub fn expect(self, msg: &str) -> T {
match self {
Ok(t) => t,
Err(e) => unwrap_failed(msg, e),
Err(e) => unwrap_failed(msg, &e),
}
}
}
Expand Down Expand Up @@ -908,7 +908,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_err(self) -> E {
match self {
Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", t),
Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", &t),
Err(e) => e,
}
}
Expand All @@ -935,7 +935,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
#[stable(feature = "result_expect_err", since = "1.17.0")]
pub fn expect_err(self, msg: &str) -> E {
match self {
Ok(t) => unwrap_failed(msg, t),
Ok(t) => unwrap_failed(msg, &t),
Err(e) => e,
}
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ impl<T, E> Result<Option<T>, E> {
// This is a separate function to reduce the code size of the methods
#[inline(never)]
#[cold]
fn unwrap_failed<E: fmt::Debug>(msg: &str, error: E) -> ! {
fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! {
panic!("{}: {:?}", msg, error)
}

Expand Down

0 comments on commit 955979a

Please sign in to comment.