about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <Thibs@debian.com>2020-10-26 11:02:01 +0100
committerThibsG <Thibs@debian.com>2020-10-26 11:15:01 +0100
commitc0dd1f9f7614d86c15fcccd4e0faabaa52c7c339 (patch)
tree22a1941339f355dacd652cf7560bc932dca9b37c
parente2d86b5b809584da55952f4150016fdbaf74e7f4 (diff)
downloadrust-c0dd1f9f7614d86c15fcccd4e0faabaa52c7c339.tar.gz
rust-c0dd1f9f7614d86c15fcccd4e0faabaa52c7c339.zip
Fix tests for `map_unwrap_or*`
-rw-r--r--tests/ui/map_unwrap_or.rs23
-rw-r--r--tests/ui/map_unwrap_or.stderr52
-rw-r--r--tests/ui/map_unwrap_or_else_fixable.stderr40
-rw-r--r--tests/ui/map_unwrap_or_fixable.fixed (renamed from tests/ui/map_unwrap_or_else_fixable.fixed)9
-rw-r--r--tests/ui/map_unwrap_or_fixable.rs (renamed from tests/ui/map_unwrap_or_else_fixable.rs)15
-rw-r--r--tests/ui/map_unwrap_or_fixable.stderr22
6 files changed, 95 insertions, 66 deletions
diff --git a/tests/ui/map_unwrap_or.rs b/tests/ui/map_unwrap_or.rs
index 4e977051ab7..87e16f5d09b 100644
--- a/tests/ui/map_unwrap_or.rs
+++ b/tests/ui/map_unwrap_or.rs
@@ -12,6 +12,10 @@ fn option_methods() {
     let opt = Some(1);
 
     // Check for `option.map(_).unwrap_or(_)` use.
+    // Single line case.
+    let _ = opt.map(|x| x + 1)
+        // Should lint even though this call is on a separate line.
+        .unwrap_or(0);
     // Multi-line cases.
     let _ = opt.map(|x| {
         x + 1
@@ -53,6 +57,25 @@ fn option_methods() {
         );
 }
 
+#[rustfmt::skip]
+fn result_methods() {
+    let res: Result<i32, ()> = Ok(1);
+
+    // Check for `result.map(_).unwrap_or_else(_)` use.
+    // multi line cases
+    let _ = res.map(|x| {
+        x + 1
+    }
+    ).unwrap_or_else(|_e| 0);
+    let _ = res.map(|x| x + 1)
+        .unwrap_or_else(|_e| {
+            0
+        });
+    // macro case
+    let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint
+}
+
 fn main() {
     option_methods();
+    result_methods();
 }
diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr
index 3fd4bdfd2b9..96b9d6cc3c1 100644
--- a/tests/ui/map_unwrap_or.stderr
+++ b/tests/ui/map_unwrap_or.stderr
@@ -1,6 +1,21 @@
 error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
   --> $DIR/map_unwrap_or.rs:16:13
    |
+LL |       let _ = opt.map(|x| x + 1)
+   |  _____________^
+LL | |         // Should lint even though this call is on a separate line.
+LL | |         .unwrap_or(0);
+   | |_____________________^
+   |
+   = note: `-D clippy::map-unwrap-or` implied by `-D warnings`
+help: use `map_or(<a>, <f>)` instead
+   |
+LL |     let _ = opt.map_or(0, |x| x + 1);
+   |                 ^^^^^^ ^^          --
+
+error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
+  --> $DIR/map_unwrap_or.rs:20:13
+   |
 LL |       let _ = opt.map(|x| {
    |  _____________^
 LL | |         x + 1
@@ -8,7 +23,6 @@ LL | |     }
 LL | |     ).unwrap_or(0);
    | |__________________^
    |
-   = note: `-D clippy::map-unwrap-or` implied by `-D warnings`
 help: use `map_or(<a>, <f>)` instead
    |
 LL |     let _ = opt.map_or(0, |x| {
@@ -18,7 +32,7 @@ LL |     );
    |
 
 error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
-  --> $DIR/map_unwrap_or.rs:20:13
+  --> $DIR/map_unwrap_or.rs:24:13
    |
 LL |       let _ = opt.map(|x| x + 1)
    |  _____________^
@@ -35,7 +49,7 @@ LL |         }, |x| x + 1);
    |
 
 error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
-  --> $DIR/map_unwrap_or.rs:25:13
+  --> $DIR/map_unwrap_or.rs:29:13
    |
 LL |     let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -46,7 +60,7 @@ LL |     let _ = opt.and_then(|x| Some(x + 1));
    |                 ^^^^^^^^                --
 
 error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
-  --> $DIR/map_unwrap_or.rs:27:13
+  --> $DIR/map_unwrap_or.rs:31:13
    |
 LL |       let _ = opt.map(|x| {
    |  _____________^
@@ -64,7 +78,7 @@ LL |     );
    |
 
 error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
-  --> $DIR/map_unwrap_or.rs:31:13
+  --> $DIR/map_unwrap_or.rs:35:13
    |
 LL |       let _ = opt
    |  _____________^
@@ -78,7 +92,7 @@ LL |         .and_then(|x| Some(x + 1));
    |          ^^^^^^^^                --
 
 error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
-  --> $DIR/map_unwrap_or.rs:42:13
+  --> $DIR/map_unwrap_or.rs:46:13
    |
 LL |     let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -89,7 +103,7 @@ LL |     let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
    |                            ^^^^^^ ^^^                      --
 
 error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or.rs:46:13
+  --> $DIR/map_unwrap_or.rs:50:13
    |
 LL |       let _ = opt.map(|x| {
    |  _____________^
@@ -99,7 +113,7 @@ LL | |     ).unwrap_or_else(|| 0);
    | |__________________________^
 
 error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or.rs:50:13
+  --> $DIR/map_unwrap_or.rs:54:13
    |
 LL |       let _ = opt.map(|x| x + 1)
    |  _____________^
@@ -108,5 +122,25 @@ LL | |             0
 LL | |         );
    | |_________^
 
-error: aborting due to 8 previous errors
+error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
+  --> $DIR/map_unwrap_or.rs:66:13
+   |
+LL |       let _ = res.map(|x| {
+   |  _____________^
+LL | |         x + 1
+LL | |     }
+LL | |     ).unwrap_or_else(|_e| 0);
+   | |____________________________^
+
+error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
+  --> $DIR/map_unwrap_or.rs:70:13
+   |
+LL |       let _ = res.map(|x| x + 1)
+   |  _____________^
+LL | |         .unwrap_or_else(|_e| {
+LL | |             0
+LL | |         });
+   | |__________^
+
+error: aborting due to 11 previous errors
 
diff --git a/tests/ui/map_unwrap_or_else_fixable.stderr b/tests/ui/map_unwrap_or_else_fixable.stderr
deleted file mode 100644
index 2cb76d70684..00000000000
--- a/tests/ui/map_unwrap_or_else_fixable.stderr
+++ /dev/null
@@ -1,40 +0,0 @@
-error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or_else_fixable.rs:17:13
-   |
-LL |       let _ = opt.map(|x| x + 1)
-   |  _____________^
-LL | |         // Should lint even though this call is on a separate line.
-LL | |         .unwrap_or_else(|| 0);
-   | |_____________________________^ help: try this: `opt.map_or_else(|| 0, |x| x + 1)`
-   |
-   = note: `-D clippy::map-unwrap-or` implied by `-D warnings`
-
-error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or_else_fixable.rs:27:13
-   |
-LL |       let _ = opt.map(|x| x + 1)
-   |  _____________^
-LL | |         // Should lint even though this call is on a separate line.
-LL | |         .unwrap_or_else(|| 0);
-   | |_____________________________^ help: try this: `opt.map_or_else(|| 0, |x| x + 1)`
-
-error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or_else_fixable.rs:52:13
-   |
-LL |     let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); // should lint even though this call is on a separate line
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
-
-error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or_else_fixable.rs:54:13
-   |
-LL |     let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
-
-error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
-  --> $DIR/map_unwrap_or_else_fixable.rs:55:13
-   |
-LL |     let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
-
-error: aborting due to 5 previous errors
-
diff --git a/tests/ui/map_unwrap_or_else_fixable.fixed b/tests/ui/map_unwrap_or_fixable.fixed
index cb2492a3be0..bd5b4f7165a 100644
--- a/tests/ui/map_unwrap_or_else_fixable.fixed
+++ b/tests/ui/map_unwrap_or_fixable.fixed
@@ -20,10 +20,6 @@ fn option_methods() {
     // Should not lint.
     let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0);
 
-    // Check for `option.map(_).unwrap_or_else(_)` use.
-    // single line case
-    let _ = opt.map_or_else(|| 0, |x| x + 1);
-
     // Issue #4144
     {
         let mut frequencies = HashMap::new();
@@ -40,15 +36,14 @@ fn option_methods() {
     }
 }
 
+#[rustfmt::skip]
 fn result_methods() {
     let res: Result<i32, ()> = Ok(1);
 
     // Check for `result.map(_).unwrap_or_else(_)` use.
     // single line case
-    let _ = res.map_or_else(|_e| 0, |x| x + 1); // should lint even though this call is on a separate line
-                                                       // multi line cases
-    let _ = res.map_or_else(|_e| 0, |x| x + 1);
     let _ = res.map_or_else(|_e| 0, |x| x + 1);
+
     // macro case
     let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint
 }
diff --git a/tests/ui/map_unwrap_or_else_fixable.rs b/tests/ui/map_unwrap_or_fixable.rs
index ed762dacd87..0b892caf20e 100644
--- a/tests/ui/map_unwrap_or_else_fixable.rs
+++ b/tests/ui/map_unwrap_or_fixable.rs
@@ -22,12 +22,6 @@ fn option_methods() {
     // Should not lint.
     let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0);
 
-    // Check for `option.map(_).unwrap_or_else(_)` use.
-    // single line case
-    let _ = opt.map(|x| x + 1)
-        // Should lint even though this call is on a separate line.
-        .unwrap_or_else(|| 0);
-
     // Issue #4144
     {
         let mut frequencies = HashMap::new();
@@ -44,15 +38,16 @@ fn option_methods() {
     }
 }
 
+#[rustfmt::skip]
 fn result_methods() {
     let res: Result<i32, ()> = Ok(1);
 
     // Check for `result.map(_).unwrap_or_else(_)` use.
     // single line case
-    let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); // should lint even though this call is on a separate line
-                                                       // multi line cases
-    let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
-    let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
+    let _ = res.map(|x| x + 1)
+        // should lint even though this call is on a separate line
+        .unwrap_or_else(|_e| 0);
+
     // macro case
     let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint
 }
diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr
new file mode 100644
index 00000000000..1837bc2ca3b
--- /dev/null
+++ b/tests/ui/map_unwrap_or_fixable.stderr
@@ -0,0 +1,22 @@
+error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
+  --> $DIR/map_unwrap_or_fixable.rs:17:13
+   |
+LL |       let _ = opt.map(|x| x + 1)
+   |  _____________^
+LL | |         // Should lint even though this call is on a separate line.
+LL | |         .unwrap_or_else(|| 0);
+   | |_____________________________^ help: try this: `opt.map_or_else(|| 0, |x| x + 1)`
+   |
+   = note: `-D clippy::map-unwrap-or` implied by `-D warnings`
+
+error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
+  --> $DIR/map_unwrap_or_fixable.rs:47:13
+   |
+LL |       let _ = res.map(|x| x + 1)
+   |  _____________^
+LL | |         // should lint even though this call is on a separate line
+LL | |         .unwrap_or_else(|_e| 0);
+   | |_______________________________^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
+
+error: aborting due to 2 previous errors
+