From eb2fdd917ef05184c7ef2eab707183b07d68ff5e Mon Sep 17 00:00:00 2001
From: Chayim Refael Friedman <chayimfr@gmail.com>
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 bca73cb770fbb..934175863630f 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -1189,6 +1189,12 @@ impl<T> Option<T> {
 
     /// 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 45b052c824d31..75dcb4cdba9e2 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -1285,6 +1285,11 @@ impl<T, E> Result<T, E> {
 
     /// 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
     ///