about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-05 19:51:09 +0000
committerbors <bors@rust-lang.org>2021-10-05 19:51:09 +0000
commitb9dedf395918275aa09710d2f51f62a1285bc035 (patch)
tree4dd016c54500ac1a01551f3d330d605107d041b7
parentabe551ecb7f0f6223f3d343a591eb34d0b332708 (diff)
parent320ecb1f0b4e41427ef7af049ce44c815bdd7664 (diff)
downloadrust-b9dedf395918275aa09710d2f51f62a1285bc035.tar.gz
rust-b9dedf395918275aa09710d2f51f62a1285bc035.zip
Auto merge of #7770 - zvavybir:master, r=xFrednet
improved help message for `suspicious_map`

`suspicious_map`'s help message assumes that the literal behavior is never the intended one, although it's sometimes.  This PR adds a mention of `inspect`, offering a idiomatic alternative.

fixes #7767

---

changelog: Improved help message of [`suspicious_map`].
-rw-r--r--clippy_lints/src/methods/mod.rs5
-rw-r--r--clippy_lints/src/methods/suspicious_map.rs2
-rw-r--r--tests/ui/suspicious_map.stderr4
3 files changed, 6 insertions, 5 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 2025056ac94..b26d11c0d6b 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -1284,8 +1284,9 @@ declare_clippy_lint! {
     ///
     /// ### Why is this bad?
     /// It looks suspicious. Maybe `map` was confused with `filter`.
-    /// If the `map` call is intentional, this should be rewritten. Or, if you intend to
-    /// drive the iterator to completion, you can just use `for_each` instead.
+    /// If the `map` call is intentional, this should be rewritten
+    /// using `inspect`. Or, if you intend to drive the iterator to
+    /// completion, you can just use `for_each` instead.
     ///
     /// ### Example
     /// ```rust
diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs
index 0fd0668c734..18ded291915 100644
--- a/clippy_lints/src/methods/suspicious_map.rs
+++ b/clippy_lints/src/methods/suspicious_map.rs
@@ -28,7 +28,7 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, count_recv: &hi
                 expr.span,
                 "this call to `map()` won't have an effect on the call to `count()`",
                 None,
-                "make sure you did not confuse `map` with `filter` or `for_each`",
+                "make sure you did not confuse `map` with `filter`, `for_each` or `inspect`",
             );
         }
     }
diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr
index 8c3f36584a5..3ffcd1a9031 100644
--- a/tests/ui/suspicious_map.stderr
+++ b/tests/ui/suspicious_map.stderr
@@ -5,7 +5,7 @@ LL |     let _ = (0..3).map(|x| x + 2).count();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::suspicious-map` implied by `-D warnings`
-   = help: make sure you did not confuse `map` with `filter` or `for_each`
+   = help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
 
 error: this call to `map()` won't have an effect on the call to `count()`
   --> $DIR/suspicious_map.rs:7:13
@@ -13,7 +13,7 @@ error: this call to `map()` won't have an effect on the call to `count()`
 LL |     let _ = (0..3).map(f).count();
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
-   = help: make sure you did not confuse `map` with `filter` or `for_each`
+   = help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
 
 error: aborting due to 2 previous errors