Skip to content

Commit 14f006a

Browse files
committed
chore
1 parent d67697f commit 14f006a

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

clippy_lints/src/methods/map_then_identity_transformer.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub(super) fn check<'tcx>(
1919
if_chain!(
2020
if let ExprKind::Closure(_, _, meth1_clos_body_id, _, _) = &meth1_clos.kind;
2121
if let ExprKind::Closure(_, _, meth2_clos_body_id, _, _) = &meth2_clos.kind;
22-
if let Some(_) = refd_param_span(cx, meth1_clos_body_id);
23-
if let Some(refd_param_span) = refd_param_span(cx, meth2_clos_body_id);
22+
if let Some(_) = refd_param_span(cx, *meth1_clos_body_id);
23+
if let Some(refd_param_span) = refd_param_span(cx, *meth2_clos_body_id);
2424
then {
2525
let meth1_clos_val = &cx.tcx.hir().body(*meth1_clos_body_id).value;
2626

@@ -37,18 +37,18 @@ pub(super) fn check<'tcx>(
3737
},
3838
);
3939
}
40-
)
40+
);
4141
}
4242

4343
// On a given closure `|.., x| y`, checks if `x` is referenced just exactly once in `y` and returns
4444
// the span of `x`
45-
fn refd_param_span<'tcx>(cx: &LateContext<'tcx>, clos_body_id: &BodyId) -> Option<Span> {
45+
fn refd_param_span<'tcx>(cx: &LateContext<'tcx>, clos_body_id: BodyId) -> Option<Span> {
46+
let clos_body = cx.tcx.hir().body(clos_body_id);
4647
if_chain! {
47-
let clos_body = cx.tcx.hir().body(*clos_body_id);
4848
if let [.., clos_param] = clos_body.params;
4949
if let PatKind::Binding(_, clos_param_id, _, _) = clos_param.pat.kind;
50-
let clos_val = &clos_body.value;
5150
then {
51+
let clos_val = &clos_body.value;
5252
let mut count = 0;
5353
let mut span = None;
5454
expr_visitor(cx, |expr| {

clippy_lints/src/methods/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1959,20 +1959,20 @@ declare_clippy_lint! {
19591959

19601960
declare_clippy_lint! {
19611961
/// ### What it does
1962-
/// Finds _.f(_).g(_) where the method calls may be collapsed together and where f and g are transformers: map, all, any, find, etc.
1962+
/// Finds `_.map(_).f(_)` where the method calls may be collapsed together and where f is a transformer: `map`, `all`, `any`, `find`, etc.
19631963
///
19641964
/// ### Why is this bad?
19651965
/// It is unnecessarily verbose and complex.
19661966
///
19671967
/// ### Example
19681968
/// ```rust
19691969
/// let iter = vec![1, 2, 3].into_iter();
1970-
/// let _ = iter.map(|x| foo(x)).flat_map(|x| bar(x));
1970+
/// let _ = iter.map(|x| x * 2).map(|x| x + 1);
19711971
/// ```
19721972
/// Use instead:
19731973
/// ```rust
19741974
/// let iter = vec![1, 2, 3].into_iter();
1975-
/// let _ = iter.flat_map(|x| bar(foo(x)));
1975+
/// let _ = iter.map(|x| x * 2 + 1);
19761976
/// ```
19771977
#[clippy::version = "1.60.0"]
19781978
pub MAP_THEN_IDENTITY_TRANSFORMER,
@@ -2062,6 +2062,7 @@ impl_lint_pass!(Methods => [
20622062
MANUAL_SPLIT_ONCE,
20632063
NEEDLESS_SPLITN,
20642064
UNNECESSARY_TO_OWNED,
2065+
MAP_THEN_IDENTITY_TRANSFORMER,
20652066
]);
20662067

20672068
/// Extracts a method call name, args, and `Span` of the method name.
@@ -2384,7 +2385,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23842385
},
23852386
("find", [f_arg]) => filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, true),
23862387
(name2 @ "map", [arg2]) => {
2387-
map_then_identity_transformer::check(cx, span2, name2, arg2, name, m_arg)
2388+
map_then_identity_transformer::check(cx, span2, name2, arg2, name, m_arg);
23882389
},
23892390
_ => {},
23902391
}

0 commit comments

Comments
 (0)