Skip to content

Commit 24f9989

Browse files
authored
Rollup merge of #101287 - Adam-Gleave:doc_bool_then_some, r=scottmcm
Document eager evaluation of `bool::then_some` argument I encountered this earlier today and thought maybe `bool::then_some` could use a little addition to the documentation. It's pretty obvious with familiarity and from looking at the implementation, but the argument for `then_some` is eagerly evaluated, which means if you do the following (as I did), you can have a problem: ```rust // Oops! let _ = something .has_another_thing() .then_some(something.another_thing_or_panic()); ``` A note, similar to other methods with eagerly-evaluated arguments and a lazy alternative (`Option::or`, for example), could help point this out to people who forget (like me)!
2 parents 36144f2 + 33afe97 commit 24f9989

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/core/src/bool.rs

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ impl bool {
66
/// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
77
/// or `None` otherwise.
88
///
9+
/// Arguments passed to `then_some` are eagerly evaluated; if you are
10+
/// passing the result of a function call, it is recommended to use
11+
/// [`then`], which is lazily evaluated.
12+
///
13+
/// [`then`]: bool::then
14+
///
915
/// # Examples
1016
///
1117
/// ```

0 commit comments

Comments
 (0)