Skip to content

Commit

Permalink
Reorder declarations of Result::expect_err/unwrap_err to match Option
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Feb 5, 2020
1 parent c00d8aa commit db9b578
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/libcore/result.rs
Expand Up @@ -998,30 +998,26 @@ impl<T: fmt::Debug, E> Result<T, E> {
///
/// # Panics
///
/// Panics if the value is an [`Ok`], with a custom panic message provided
/// by the [`Ok`]'s value.
/// Panics if the value is an [`Ok`], with a panic message including the
/// passed message, and the content of the [`Ok`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
///
/// # Examples
///
/// ```{.should_panic}
/// let x: Result<u32, &str> = Ok(2);
/// x.unwrap_err(); // panics with `2`
/// ```
/// Basic usage:
///
/// ```
/// let x: Result<u32, &str> = Err("emergency failure");
/// assert_eq!(x.unwrap_err(), "emergency failure");
/// ```{.should_panic}
/// let x: Result<u32, &str> = Ok(10);
/// x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
/// ```
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_err(self) -> E {
#[stable(feature = "result_expect_err", since = "1.17.0")]
pub fn expect_err(self, msg: &str) -> E {
match self {
Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", &t),
Ok(t) => unwrap_failed(msg, &t),
Err(e) => e,
}
}
Expand All @@ -1030,26 +1026,30 @@ impl<T: fmt::Debug, E> Result<T, E> {
///
/// # Panics
///
/// Panics if the value is an [`Ok`], with a panic message including the
/// passed message, and the content of the [`Ok`].
/// Panics if the value is an [`Ok`], with a custom panic message provided
/// by the [`Ok`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
/// # Examples
///
/// ```{.should_panic}
/// let x: Result<u32, &str> = Ok(10);
/// x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
/// let x: Result<u32, &str> = Ok(2);
/// x.unwrap_err(); // panics with `2`
/// ```
///
/// ```
/// let x: Result<u32, &str> = Err("emergency failure");
/// assert_eq!(x.unwrap_err(), "emergency failure");
/// ```
#[inline]
#[track_caller]
#[stable(feature = "result_expect_err", since = "1.17.0")]
pub fn expect_err(self, msg: &str) -> E {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_err(self) -> E {
match self {
Ok(t) => unwrap_failed(msg, &t),
Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", &t),
Err(e) => e,
}
}
Expand Down

0 comments on commit db9b578

Please sign in to comment.