]> git.lizzy.rs Git - rust.git/commitdiff
Fix bug. Don't expect lint when acc is on rhs
authorPhil Ellison <phil.j.ellison@gmail.com>
Wed, 17 Jan 2018 20:11:40 +0000 (20:11 +0000)
committerPhil Ellison <phil.j.ellison@gmail.com>
Wed, 17 Jan 2018 20:11:40 +0000 (20:11 +0000)
tests/ui/methods.rs
tests/ui/methods.stderr

index 3ca77f744fe09ea91dac30b9226ccc87545a63fc..f7a4b39c7a6f205c090aa0882e64ea21a427fe08 100644 (file)
@@ -389,19 +389,12 @@ fn iter_skip_next() {
 fn unnecessary_fold() {
     // Can be replaced by .any
     let _ = (0..3).fold(false, |acc, x| acc || x > 2);
-    let _ = (0..3).fold(false, |acc, x| x > 2 || acc);
-
     // Can be replaced by .all
     let _ = (0..3).fold(true, |acc, x| acc && x > 2);
-    let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
-
     // Can be replaced by .sum
     let _ = (0..3).fold(0, |acc, x| acc + x);
-    let _ = (0..3).fold(0, |acc, x| x + acc);
-
     // Can be replaced by .product
     let _ = (0..3).fold(1, |acc, x| acc * x);
-    let _ = (0..3).fold(1, |acc, x| x * acc);
 }
 
 /// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)`
@@ -416,6 +409,16 @@ fn unnecessary_fold_should_ignore() {
     let _ = (0..3).fold(1, |acc, x| acc + x);
     let _ = (0..3).fold(0, |acc, x| acc * x);
     let _ = (0..3).fold(0, |acc, x| 1 + acc + x);
+
+    // We only match against an accumulator on the left
+    // hand side. We could lint for .sum and .product when
+    // it's on the right, but don't for now (and this wouldn't
+    // be valid if we extended the lint to cover arbitrary numeric
+    // types).
+    let _ = (0..3).fold(false, |acc, x| x > 2 || acc);
+    let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
+    let _ = (0..3).fold(0, |acc, x| x + acc);
+    let _ = (0..3).fold(1, |acc, x| x * acc);
 }
 
 #[allow(similar_names)]
index 1c8569e8d6ba3c9e92db0b9ccad15380d8183806..57f073f00b040d1c8dd0bfb1312b5250df94c926 100644 (file)
@@ -502,33 +502,33 @@ error: this `.fold` can be written more succinctly using another method
     = note: `-D fold-any` implied by `-D warnings`
 
 error: this `.fold` can be written more succinctly using another method
-   --> $DIR/methods.rs:395:19
+   --> $DIR/methods.rs:393:19
     |
-395 |     let _ = (0..3).fold(true, |acc, x| acc && x > 2);
+393 |     let _ = (0..3).fold(true, |acc, x| acc && x > 2);
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.all(|x| x > 2)`
 
 error: this `.fold` can be written more succinctly using another method
-   --> $DIR/methods.rs:399:19
+   --> $DIR/methods.rs:395:19
     |
-399 |     let _ = (0..3).fold(0, |acc, x| acc + x);
-    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.sum(|x| x)`
+395 |     let _ = (0..3).fold(0, |acc, x| acc + x);
+    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.sum()`
 
 error: this `.fold` can be written more succinctly using another method
-   --> $DIR/methods.rs:403:19
+   --> $DIR/methods.rs:397:19
     |
-403 |     let _ = (0..3).fold(1, |acc, x| acc * x);
-    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.product(|x| x)`
+397 |     let _ = (0..3).fold(1, |acc, x| acc * x);
+    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.product()`
 
 error: this `.fold` can be written more succinctly using another method
-   --> $DIR/methods.rs:409:34
+   --> $DIR/methods.rs:402:34
     |
-409 |     let _ = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
+402 |     let _ = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
     |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
 
 error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
-   --> $DIR/methods.rs:424:13
+   --> $DIR/methods.rs:427:13
     |
-424 |     let _ = opt.unwrap();
+427 |     let _ = opt.unwrap();
     |             ^^^^^^^^^^^^
     |
     = note: `-D option-unwrap-used` implied by `-D warnings`