Skip to content

Commit 7ba0be8

Browse files
committed
add same warning to Result::expect as Result::unwrap
1 parent 62b272d commit 7ba0be8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/src/result.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,15 @@ impl<T, E> Result<T, E> {
10091009

10101010
/// Returns the contained [`Ok`] value, consuming the `self` value.
10111011
///
1012+
/// Because this function may panic, its use is generally discouraged.
1013+
/// Instead, prefer to use pattern matching and handle the [`Err`]
1014+
/// case explicitly, or call [`unwrap_or`], [`unwrap_or_else`], or
1015+
/// [`unwrap_or_default`].
1016+
///
1017+
/// [`unwrap_or`]: Result::unwrap_or
1018+
/// [`unwrap_or_else`]: Result::unwrap_or_else
1019+
/// [`unwrap_or_default`]: Result::unwrap_or_default
1020+
///
10121021
/// # Panics
10131022
///
10141023
/// Panics if the value is an [`Err`], with a panic message including the

0 commit comments

Comments
 (0)