Skip to content

Commit

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

/// Unwraps a result, yielding the content of an [`Ok`].
///
/// # Panics
///
/// Panics if the value is an [`Err`], with a panic message including the
/// passed message, and the content of the [`Err`].
/// Panics if the value is an [`Err`], with a panic message provided by the
/// [`Err`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
Expand All @@ -978,17 +973,22 @@ impl<T, E: fmt::Debug> Result<T, E> {
///
/// Basic usage:
///
/// ```
/// let x: Result<u32, &str> = Ok(2);
/// assert_eq!(x.unwrap(), 2);
/// ```
///
/// ```{.should_panic}
/// let x: Result<u32, &str> = Err("emergency failure");
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
/// x.unwrap(); // panics with `emergency failure`
/// ```
#[inline]
#[track_caller]
#[stable(feature = "result_expect", since = "1.4.0")]
pub fn expect(self, msg: &str) -> T {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap(self) -> T {
match self {
Ok(t) => t,
Err(e) => unwrap_failed(msg, &e),
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", &e),
}
}
}
Expand Down

0 comments on commit c00d8aa

Please sign in to comment.