Skip to content

Commit 5d98acb

Browse files
committed
update docs for option to crossreference to the result docs
1 parent 80c362b commit 5d98acb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

library/core/src/option.rs

+3
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ impl<T> Option<T> {
708708
/// let x: Option<&str> = None;
709709
/// x.expect("fruits are healthy"); // panics with `fruits are healthy`
710710
/// ```
711+
///
712+
/// **Note**: Please refer to the documentation on [`Result::expect`] for further information
713+
/// on common message styles.
711714
#[inline]
712715
#[track_caller]
713716
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/result.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,8 @@ impl<T, E> Result<T, E> {
10471047
/// .expect("env variable `IMPORTANT_PATH` is not set");
10481048
/// ```
10491049
///
1050-
/// In the latter style, we would instead describe the reason we _expect_ the `Result` will
1051-
/// always be `Ok`. With this style we would instead write:
1050+
/// In the "expect as precondition" style, we would instead describe the reason we _expect_ the
1051+
/// `Result` will always be `Ok`. With this style we would prefer to write:
10521052
///
10531053
/// ```should_panic
10541054
/// let path = std::env::var("IMPORTANT_PATH")
@@ -1060,7 +1060,7 @@ impl<T, E> Result<T, E> {
10601060
/// `std`.
10611061
///
10621062
/// ```text
1063-
/// thread 'expect_as_error_message' panicked at 'env variable `IMPORTANT_PATH` is not set: NotPresent', src/lib.rs:4:10
1063+
/// thread 'main' panicked at 'env variable `IMPORTANT_PATH` is not set: NotPresent', src/main.rs:4:6
10641064
/// ```
10651065
///
10661066
/// The "expect as precondition" style instead focuses on source code readability, making it
@@ -1069,13 +1069,13 @@ impl<T, E> Result<T, E> {
10691069
/// directly to users with the default `std` panic hook's report format:
10701070
///
10711071
/// ```text
1072-
/// thread 'expect_as_precondition' panicked at 'env variable `IMPORTANT_PATH` is always set by `wrapper_script.sh`: NotPresent', src/lib.rs:4:10
1072+
/// thread 'main' panicked at 'env variable `IMPORTANT_PATH` is always be set by `wrapper_script.sh`: NotPresent', src/main.rs:4:6
10731073
/// ```
10741074
///
10751075
/// This style works best when paired with a custom [panic hook] like the one provided by the
1076-
/// CLI working group library, [`human-panic`], which redirects panic messages to crash report
1077-
/// files while showing users a more "Oops, something went wrong!" message with a suggestion to
1078-
/// send the crash report file back to the developers.
1076+
/// CLI working group library, [`human-panic`], which dumps the panic messages to a crash
1077+
/// report file while showing users a more friendly "Oops, something went wrong!" message with
1078+
/// a suggestion to send the crash report file back to the developers.
10791079
///
10801080
/// [panic hook]: https://doc.rust-lang.org/stable/std/panic/fn.set_hook.html
10811081
/// [`human-panic`]: https://docs.rs/human-panic

0 commit comments

Comments
 (0)