@@ -998,30 +998,26 @@ impl<T: fmt::Debug, E> Result<T, E> {
998
998
///
999
999
/// # Panics
1000
1000
///
1001
- /// Panics if the value is an [`Ok`], with a custom panic message provided
1002
- /// by the [`Ok`]'s value .
1001
+ /// Panics if the value is an [`Ok`], with a panic message including the
1002
+ /// passed message, and the content of the [`Ok`].
1003
1003
///
1004
1004
/// [`Ok`]: enum.Result.html#variant.Ok
1005
1005
/// [`Err`]: enum.Result.html#variant.Err
1006
1006
///
1007
- ///
1008
1007
/// # Examples
1009
1008
///
1010
- /// ```{.should_panic}
1011
- /// let x: Result<u32, &str> = Ok(2);
1012
- /// x.unwrap_err(); // panics with `2`
1013
- /// ```
1009
+ /// Basic usage:
1014
1010
///
1015
- /// ```
1016
- /// let x: Result<u32, &str> = Err("emergency failure" );
1017
- /// assert_eq!(x.unwrap_err(), "emergency failure ");
1011
+ /// ```{.should_panic}
1012
+ /// let x: Result<u32, &str> = Ok(10 );
1013
+ /// x.expect_err("Testing expect_err "); // panics with `Testing expect_err: 10`
1018
1014
/// ```
1019
1015
#[ inline]
1020
1016
#[ track_caller]
1021
- #[ stable( feature = "rust1 " , since = "1.0 .0" ) ]
1022
- pub fn unwrap_err ( self ) -> E {
1017
+ #[ stable( feature = "result_expect_err " , since = "1.17 .0" ) ]
1018
+ pub fn expect_err ( self , msg : & str ) -> E {
1023
1019
match self {
1024
- Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , & t) ,
1020
+ Ok ( t) => unwrap_failed ( msg , & t) ,
1025
1021
Err ( e) => e,
1026
1022
}
1027
1023
}
@@ -1030,26 +1026,30 @@ impl<T: fmt::Debug, E> Result<T, E> {
1030
1026
///
1031
1027
/// # Panics
1032
1028
///
1033
- /// Panics if the value is an [`Ok`], with a panic message including the
1034
- /// passed message, and the content of the [`Ok`].
1029
+ /// Panics if the value is an [`Ok`], with a custom panic message provided
1030
+ /// by the [`Ok`]'s value .
1035
1031
///
1036
1032
/// [`Ok`]: enum.Result.html#variant.Ok
1037
1033
/// [`Err`]: enum.Result.html#variant.Err
1038
1034
///
1039
- /// # Examples
1040
1035
///
1041
- /// Basic usage:
1036
+ /// # Examples
1042
1037
///
1043
1038
/// ```{.should_panic}
1044
- /// let x: Result<u32, &str> = Ok(10);
1045
- /// x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
1039
+ /// let x: Result<u32, &str> = Ok(2);
1040
+ /// x.unwrap_err(); // panics with `2`
1041
+ /// ```
1042
+ ///
1043
+ /// ```
1044
+ /// let x: Result<u32, &str> = Err("emergency failure");
1045
+ /// assert_eq!(x.unwrap_err(), "emergency failure");
1046
1046
/// ```
1047
1047
#[ inline]
1048
1048
#[ track_caller]
1049
- #[ stable( feature = "result_expect_err " , since = "1.17 .0" ) ]
1050
- pub fn expect_err ( self , msg : & str ) -> E {
1049
+ #[ stable( feature = "rust1 " , since = "1.0 .0" ) ]
1050
+ pub fn unwrap_err ( self ) -> E {
1051
1051
match self {
1052
- Ok ( t) => unwrap_failed ( msg , & t) ,
1052
+ Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , & t) ,
1053
1053
Err ( e) => e,
1054
1054
}
1055
1055
}
0 commit comments