about summary refs log tree commit diff
diff options
context:
space:
mode:
authortogami2864 <tuabobo123@gmail.com>2021-11-15 15:47:57 +0900
committertogami2864 <tuabobo123@gmail.com>2021-11-15 15:47:57 +0900
commit4f71ff3f847e7da299be5cc3ba00ebfda5899166 (patch)
treec83b285b1f1b8ac67fb64a63877e513f094e105c
parent2ed4a8a3e6fc8d53225ded631e815a767859184e (diff)
downloadrust-4f71ff3f847e7da299be5cc3ba00ebfda5899166.tar.gz
rust-4f71ff3f847e7da299be5cc3ba00ebfda5899166.zip
add test case for option_map_or_none
-rw-r--r--tests/ui/option_map_or_none.fixed11
-rw-r--r--tests/ui/option_map_or_none.rs9
-rw-r--r--tests/ui/option_map_or_none.stderr18
3 files changed, 27 insertions, 11 deletions
diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed
index 429ef00003f..77ad2d5285a 100644
--- a/tests/ui/option_map_or_none.fixed
+++ b/tests/ui/option_map_or_none.fixed
@@ -4,13 +4,18 @@
 
 fn main() {
     let opt = Some(1);
+    let bar = |_| {
+       Some(1)
+    };
 
     // Check `OPTION_MAP_OR_NONE`.
     // Single line case.
-    let _ = opt.map(|x| Some(x + 1));
+    let _ :Option<i32> = opt.map(|x| x + 1);
     // Multi-line case.
     #[rustfmt::skip]
-    let _ = opt.map(|x| {
-                        Some(x + 1)
+    let _ :Option<i32> = opt.map(|x| {
+                        x + 1
                        });
+    // function returning `Option`
+    let _ :Option<i32> = opt.and_then(bar);
 }
diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs
index 629842419e5..789531b7215 100644
--- a/tests/ui/option_map_or_none.rs
+++ b/tests/ui/option_map_or_none.rs
@@ -4,13 +4,18 @@
 
 fn main() {
     let opt = Some(1);
+    let bar = |_| {
+        Some(1)
+    };
 
     // Check `OPTION_MAP_OR_NONE`.
     // Single line case.
-    let _ = opt.map_or(None, |x| Some(x + 1));
+    let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
     // Multi-line case.
     #[rustfmt::skip]
-    let _ = opt.map_or(None, |x| {
+    let _ :Option<i32> = opt.map_or(None, |x| {
                         Some(x + 1)
                        });
+    // function returning `Option`
+    let _ :Option<i32> = opt.map_or(None, bar);
 }
diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr
index b011515934d..86ac93b9c80 100644
--- a/tests/ui/option_map_or_none.stderr
+++ b/tests/ui/option_map_or_none.stderr
@@ -1,15 +1,15 @@
 error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
   --> $DIR/option_map_or_none.rs:10:13
    |
-LL |     let _ = opt.map_or(None, |x| Some(x + 1));
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| Some(x + 1))`
+LL |     let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)`
    |
    = note: `-D clippy::option-map-or-none` implied by `-D warnings`
 
 error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
   --> $DIR/option_map_or_none.rs:13:13
    |
-LL |       let _ = opt.map_or(None, |x| {
+LL |       let _ :Option<i32> = opt.map_or(None, |x| {
    |  _____________^
 LL | |                         Some(x + 1)
 LL | |                        });
@@ -17,10 +17,16 @@ LL | |                        });
    |
 help: try using `map` instead
    |
-LL ~     let _ = opt.map(|x| {
-LL +                         Some(x + 1)
+LL ~     let _ :Option<i32> = opt.map(|x| {
+LL +                         x + 1
 LL ~                        });
    |
 
-error: aborting due to 2 previous errors
+error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
+  --> $DIR/option_map_or_none.rs:20:26
+   |
+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