From 8e317f5283969aa775552e659d4219bb2641954a Mon Sep 17 00:00:00 2001
From: togami2864 <tuabobo123@gmail.com>
Date: Thu, 18 Nov 2021 00:43:49 +0900
Subject: [PATCH] fix suggestion message

---
 tests/ui/option_map_or_none.fixed  |  5 +++++
 tests/ui/option_map_or_none.rs     |  2 +-
 tests/ui/option_map_or_none.stderr | 22 +++++++++++++++++++++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed
index abaf88be8ca..177054f763b 100644
--- a/tests/ui/option_map_or_none.fixed
+++ b/tests/ui/option_map_or_none.fixed
@@ -14,4 +14,9 @@ fn main() {
     let _: Option<i32> = opt.map(|x| x + 1);
     // function returning `Option`
     let _: Option<i32> = opt.and_then(bar);
+    let _: Option<i32> = opt.and_then(|x| {
+        let offset = 0;
+        let height = x;
+        Some(offset + height)
+    });
 }
diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs
index 0d24d754820..6908546d325 100644
--- a/tests/ui/option_map_or_none.rs
+++ b/tests/ui/option_map_or_none.rs
@@ -18,7 +18,7 @@ fn main() {
     let _: Option<i32> = opt.map_or(None, bar);
     let _: Option<i32> = opt.map_or(None, |x| {
         let offset = 0;
-        let height = 1;
+        let height = x;
         Some(offset + height)
     });
 }
diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr
index aec46cb005f..11bdd887b6d 100644
--- a/tests/ui/option_map_or_none.stderr
+++ b/tests/ui/option_map_or_none.stderr
@@ -21,5 +21,25 @@ error: called `map_or(None, ..)` on an `Option` value. This can be done more dir
 LL |     let _: Option<i32> = opt.map_or(None, bar);
    |                          ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
 
-error: aborting due to 3 previous errors
+error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
+  --> $DIR/option_map_or_none.rs:19:26
+   |
+LL |       let _: Option<i32> = opt.map_or(None, |x| {
+   |  __________________________^
+LL | |         let offset = 0;
+LL | |         let height = x;
+LL | |         Some(offset + height)
+LL | |     });
+   | |______^
+   |
+help: try using `and_then` instead
+   |
+LL ~     let _: Option<i32> = opt.and_then(|x| {
+LL +         let offset = 0;
+LL +         let height = x;
+LL +         Some(offset + height)
+LL ~     });
+   |
+
+error: aborting due to 4 previous errors