about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/option_map_or_none.fixed5
-rw-r--r--tests/ui/option_map_or_none.rs2
-rw-r--r--tests/ui/option_map_or_none.stderr22
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