Skip to content

Commit c00d8aa

Browse files
committed
Reorder declarations of Result::export/unwrap to match Option
1 parent 002287d commit c00d8aa

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/libcore/result.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ impl<T, E: fmt::Debug> Result<T, E> {
935935
///
936936
/// # Panics
937937
///
938-
/// Panics if the value is an [`Err`], with a panic message provided by the
939-
/// [`Err`]'s value.
938+
/// Panics if the value is an [`Err`], with a panic message including the
939+
/// passed message, and the content of the [`Err`].
940940
///
941941
/// [`Ok`]: enum.Result.html#variant.Ok
942942
/// [`Err`]: enum.Result.html#variant.Err
@@ -945,31 +945,26 @@ impl<T, E: fmt::Debug> Result<T, E> {
945945
///
946946
/// Basic usage:
947947
///
948-
/// ```
949-
/// let x: Result<u32, &str> = Ok(2);
950-
/// assert_eq!(x.unwrap(), 2);
951-
/// ```
952-
///
953948
/// ```{.should_panic}
954949
/// let x: Result<u32, &str> = Err("emergency failure");
955-
/// x.unwrap(); // panics with `emergency failure`
950+
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
956951
/// ```
957952
#[inline]
958953
#[track_caller]
959-
#[stable(feature = "rust1", since = "1.0.0")]
960-
pub fn unwrap(self) -> T {
954+
#[stable(feature = "result_expect", since = "1.4.0")]
955+
pub fn expect(self, msg: &str) -> T {
961956
match self {
962957
Ok(t) => t,
963-
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", &e),
958+
Err(e) => unwrap_failed(msg, &e),
964959
}
965960
}
966961

967962
/// Unwraps a result, yielding the content of an [`Ok`].
968963
///
969964
/// # Panics
970965
///
971-
/// Panics if the value is an [`Err`], with a panic message including the
972-
/// passed message, and the content of the [`Err`].
966+
/// Panics if the value is an [`Err`], with a panic message provided by the
967+
/// [`Err`]'s value.
973968
///
974969
/// [`Ok`]: enum.Result.html#variant.Ok
975970
/// [`Err`]: enum.Result.html#variant.Err
@@ -978,17 +973,22 @@ impl<T, E: fmt::Debug> Result<T, E> {
978973
///
979974
/// Basic usage:
980975
///
976+
/// ```
977+
/// let x: Result<u32, &str> = Ok(2);
978+
/// assert_eq!(x.unwrap(), 2);
979+
/// ```
980+
///
981981
/// ```{.should_panic}
982982
/// let x: Result<u32, &str> = Err("emergency failure");
983-
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
983+
/// x.unwrap(); // panics with `emergency failure`
984984
/// ```
985985
#[inline]
986986
#[track_caller]
987-
#[stable(feature = "result_expect", since = "1.4.0")]
988-
pub fn expect(self, msg: &str) -> T {
987+
#[stable(feature = "rust1", since = "1.0.0")]
988+
pub fn unwrap(self) -> T {
989989
match self {
990990
Ok(t) => t,
991-
Err(e) => unwrap_failed(msg, &e),
991+
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", &e),
992992
}
993993
}
994994
}

0 commit comments

Comments
 (0)