From eb2fdd917ef05184c7ef2eab707183b07d68ff5e Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Tue, 23 Aug 2022 16:15:09 +0000 Subject: [PATCH] Add a warning about `Option/Result::and()` being eagerly evaluated Copied from `or()`. --- library/core/src/option.rs | 6 ++++++ library/core/src/result.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index bca73cb770fb..934175863630 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1189,6 +1189,12 @@ impl Option { /// Returns [`None`] if the option is [`None`], otherwise returns `optb`. /// + /// Arguments passed to `and` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use [`and_then`], which is + /// lazily evaluated. + /// + /// [`and_then`]: Option::and_then + /// /// # Examples /// /// ``` diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 45b052c824d3..75dcb4cdba9e 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1285,6 +1285,11 @@ impl Result { /// Returns `res` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`. /// + /// Arguments passed to `and` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use [`and_then`], which is + /// lazily evaluated. + /// + /// [`and_then`]: Result::and_then /// /// # Examples ///