Skip to content

Commit 720e987

Browse files
committed
update option and result references to expect message docs
1 parent b6b621e commit 720e987

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

library/core/src/option.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,24 @@ impl<T> Option<T> {
709709
/// x.expect("fruits are healthy"); // panics with `fruits are healthy`
710710
/// ```
711711
///
712-
/// **Note**: Please refer to the documentation on [`Result::expect`] for further information
713-
/// on common message styles.
712+
/// # Recommended Message Style
713+
///
714+
/// We recommend that `expect` messages are used to describe the reason you
715+
/// _expect_ the `Option` should be `Some`.
716+
///
717+
/// ```should_panic
718+
/// let item = slice.get(0)
719+
/// .expect("slice should not be empty");
720+
/// ```
721+
///
722+
/// **Hint**: If you're having trouble remembering how to phrase expect
723+
/// error messages remember to focus on the word "should" as in "env
724+
/// variable should be set by blah" or "the given binary should be available
725+
/// and executable by the current user".
726+
///
727+
/// For more detail on expect message styles and the reasoning behind our
728+
/// recommendation please refer to the section on ["Common Message
729+
/// Styles"](../../std/error/index.html#common-message-styles) in the [`std::error`](../../std/error/index.html) module docs.
714730
#[inline]
715731
#[track_caller]
716732
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/result.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,15 @@ impl<T, E> Result<T, E> {
10341034
/// .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`");
10351035
/// ```
10361036
///
1037-
/// For more detail on expect message styles and the reasoning behind our
1038-
/// recommendation please refer to the section on ["Common Message
1039-
/// Styles"]() in the [`std::error`]() module docs.
1037+
/// **Hint**: If you're having trouble remembering how to phrase expect
1038+
/// error messages remember to focus on the word "should" as in "env
1039+
/// variable should be set by blah" or "the given binary should be available
1040+
/// and executable by the current user".
1041+
///
1042+
/// For more detail on expect message styles and the reasoning behind our recommendation please
1043+
/// refer to the section on ["Common Message
1044+
/// Styles"](../../std/error/index.html#common-message-styles) in the
1045+
/// [`std::error`](../../std/error/index.html) module docs.
10401046
#[inline]
10411047
#[track_caller]
10421048
#[stable(feature = "result_expect", since = "1.4.0")]

0 commit comments

Comments
 (0)