@@ -792,8 +792,7 @@ impl<T, E> Result<T, E> {
792792 }
793793 }
794794
795- /// Unwraps a result, yielding the content of an [`Ok`].
796- /// Else, it returns `optb`.
795+ /// Returns the contained [`Ok`] value or a provided default.
797796 ///
798797 /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing
799798 /// the result of a function call, it is recommended to use [`unwrap_or_else`],
@@ -808,27 +807,25 @@ impl<T, E> Result<T, E> {
808807 /// Basic usage:
809808 ///
810809 /// ```
811- /// let optb = 2;
810+ /// let default = 2;
812811 /// let x: Result<u32, &str> = Ok(9);
813- /// assert_eq!(x.unwrap_or(optb ), 9);
812+ /// assert_eq!(x.unwrap_or(default ), 9);
814813 ///
815814 /// let x: Result<u32, &str> = Err("error");
816- /// assert_eq!(x.unwrap_or(optb ), optb );
815+ /// assert_eq!(x.unwrap_or(default ), default );
817816 /// ```
818817 #[ inline]
819818 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
820- pub fn unwrap_or ( self , optb : T ) -> T {
819+ pub fn unwrap_or ( self , default : T ) -> T {
821820 match self {
822821 Ok ( t) => t,
823- Err ( _) => optb ,
822+ Err ( _) => default ,
824823 }
825824 }
826825
827- /// Unwraps a result, yielding the content of an [`Ok`].
828- /// If the value is an [`Err`] then it calls `op` with its value.
826+ /// Returns the contained [`Ok`] value or computes it from a closure.
829827 ///
830828 /// [`Ok`]: enum.Result.html#variant.Ok
831- /// [`Err`]: enum.Result.html#variant.Err
832829 ///
833830 /// # Examples
834831 ///
@@ -931,7 +928,7 @@ impl<T: Clone, E> Result<&mut T, E> {
931928}
932929
933930impl < T , E : fmt:: Debug > Result < T , E > {
934- /// Unwraps a result, yielding the content of an [`Ok`].
931+ /// Returns the contained [`Ok`] value, consuming the `self` value .
935932 ///
936933 /// # Panics
937934 ///
@@ -959,7 +956,16 @@ impl<T, E: fmt::Debug> Result<T, E> {
959956 }
960957 }
961958
962- /// Unwraps a result, yielding the content of an [`Ok`].
959+ /// Returns the contained [`Ok`] value, consuming the `self` value.
960+ ///
961+ /// Because this function may panic, its use is generally discouraged.
962+ /// Instead, prefer to use pattern matching and handle the [`Err`]
963+ /// case explicitly, or call [`unwrap_or`], [`unwrap_or_else`], or
964+ /// [`unwrap_or_default`].
965+ ///
966+ /// [`unwrap_or`]: #method.unwrap_or
967+ /// [`unwrap_or_else`]: #method.unwrap_or_else
968+ /// [`unwrap_or_default`]: #method.unwrap_or_default
963969 ///
964970 /// # Panics
965971 ///
@@ -994,7 +1000,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
9941000}
9951001
9961002impl < T : fmt:: Debug , E > Result < T , E > {
997- /// Unwraps a result, yielding the content of an [`Err`].
1003+ /// Returns the contained [`Err`] value, consuming the `self` value .
9981004 ///
9991005 /// # Panics
10001006 ///
@@ -1022,7 +1028,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
10221028 }
10231029 }
10241030
1025- /// Unwraps a result, yielding the content of an [`Err`].
1031+ /// Returns the contained [`Err`] value, consuming the `self` value .
10261032 ///
10271033 /// # Panics
10281034 ///
@@ -1056,7 +1062,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
10561062}
10571063
10581064impl < T : Default , E > Result < T , E > {
1059- /// Returns the contained value or a default
1065+ /// Returns the contained [`Ok`] value or a default
10601066 ///
10611067 /// Consumes the `self` argument then, if [`Ok`], returns the contained
10621068 /// value, otherwise if [`Err`], returns the default value for that
@@ -1095,7 +1101,7 @@ impl<T: Default, E> Result<T, E> {
10951101
10961102#[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
10971103impl < T , E : Into < !> > Result < T , E > {
1098- /// Unwraps a result that can never be an [`Err`], yielding the content of the [`Ok`] .
1104+ /// Returns the contained [`Ok`] value, but never panics .
10991105 ///
11001106 /// Unlike [`unwrap`], this method is known to never panic on the
11011107 /// result types it is implemented for. Therefore, it can be used
0 commit comments