Skip to content

Commit b9dedf3

Browse files
committed
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`].
2 parents abe551e + 320ecb1 commit b9dedf3

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,9 @@ declare_clippy_lint! {
12841284
///
12851285
/// ### Why is this bad?
12861286
/// It looks suspicious. Maybe `map` was confused with `filter`.
1287-
/// If the `map` call is intentional, this should be rewritten. Or, if you intend to
1288-
/// drive the iterator to completion, you can just use `for_each` instead.
1287+
/// If the `map` call is intentional, this should be rewritten
1288+
/// using `inspect`. Or, if you intend to drive the iterator to
1289+
/// completion, you can just use `for_each` instead.
12891290
///
12901291
/// ### Example
12911292
/// ```rust

clippy_lints/src/methods/suspicious_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, count_recv: &hi
2828
expr.span,
2929
"this call to `map()` won't have an effect on the call to `count()`",
3030
None,
31-
"make sure you did not confuse `map` with `filter` or `for_each`",
31+
"make sure you did not confuse `map` with `filter`, `for_each` or `inspect`",
3232
);
3333
}
3434
}

tests/ui/suspicious_map.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ LL | let _ = (0..3).map(|x| x + 2).count();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::suspicious-map` implied by `-D warnings`
8-
= help: make sure you did not confuse `map` with `filter` or `for_each`
8+
= help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
99

1010
error: this call to `map()` won't have an effect on the call to `count()`
1111
--> $DIR/suspicious_map.rs:7:13
1212
|
1313
LL | let _ = (0..3).map(f).count();
1414
| ^^^^^^^^^^^^^^^^^^^^^
1515
|
16-
= help: make sure you did not confuse `map` with `filter` or `for_each`
16+
= help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
1717

1818
error: aborting due to 2 previous errors
1919

0 commit comments

Comments
 (0)