@@ -998,30 +998,26 @@ impl<T: fmt::Debug, E> Result<T, E> {
998998 ///
999999 /// # Panics
10001000 ///
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`].
10031003 ///
10041004 /// [`Ok`]: enum.Result.html#variant.Ok
10051005 /// [`Err`]: enum.Result.html#variant.Err
10061006 ///
1007- ///
10081007 /// # Examples
10091008 ///
1010- /// ```{.should_panic}
1011- /// let x: Result<u32, &str> = Ok(2);
1012- /// x.unwrap_err(); // panics with `2`
1013- /// ```
1009+ /// Basic usage:
10141010 ///
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`
10181014 /// ```
10191015 #[ inline]
10201016 #[ 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 {
10231019 match self {
1024- Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , & t) ,
1020+ Ok ( t) => unwrap_failed ( msg , & t) ,
10251021 Err ( e) => e,
10261022 }
10271023 }
@@ -1030,26 +1026,30 @@ impl<T: fmt::Debug, E> Result<T, E> {
10301026 ///
10311027 /// # Panics
10321028 ///
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 .
10351031 ///
10361032 /// [`Ok`]: enum.Result.html#variant.Ok
10371033 /// [`Err`]: enum.Result.html#variant.Err
10381034 ///
1039- /// # Examples
10401035 ///
1041- /// Basic usage:
1036+ /// # Examples
10421037 ///
10431038 /// ```{.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");
10461046 /// ```
10471047 #[ inline]
10481048 #[ 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 {
10511051 match self {
1052- Ok ( t) => unwrap_failed ( msg , & t) ,
1052+ Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , & t) ,
10531053 Err ( e) => e,
10541054 }
10551055 }
0 commit comments