Skip to content

Commit

Permalink
Auto merge of rust-lang#7770 - zvavybir:master, r=xFrednet
Browse files Browse the repository at this point in the history
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 rust-lang#7767

---

changelog: Improved help message of [`suspicious_map`].
  • Loading branch information
bors committed Oct 5, 2021
2 parents abe551e + 320ecb1 commit b9dedf3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/suspicious_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suspicious_map.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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
|
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

0 comments on commit b9dedf3

Please sign in to comment.