Skip to content

Commit 5fd7d44

Browse files
Refactor if_chain
Co-authored-by: Philipp Krones <[email protected]>
1 parent b651f19 commit 5fd7d44

File tree

1 file changed

+25
-24
lines changed
  • clippy_lints/src/methods

1 file changed

+25
-24
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,38 +2174,39 @@ fn lint_flat_map_identity<'a, 'tcx>(
21742174
if match_trait_method(cx, expr, &paths::ITERATOR);
21752175

21762176
if flat_map_args.len() == 2;
2177-
if let hir::ExprKind::Closure(_, _, body_id, _, _) = flat_map_args[1].node;
2178-
let body = cx.tcx.hir().body(body_id);
2179-
2180-
if body.arguments.len() == 1;
2181-
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
2182-
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
2183-
2184-
if path.segments.len() == 1;
2185-
if path.segments[0].ident.as_str() == binding_ident.as_str();
21862177

21872178
then {
2188-
let msg = "called `flat_map(|x| x)` on an `Iterator`. \
2189-
This can be simplified by calling `flatten().`";
2190-
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
2191-
}
2192-
}
2179+
if_chain! {
2180+
if let hir::ExprKind::Closure(_, _, body_id, _, _) = flat_map_args[1].node;
2181+
let body = cx.tcx.hir().body(body_id);
21932182

2194-
if_chain! {
2195-
if match_trait_method(cx, expr, &paths::ITERATOR);
2183+
if body.arguments.len() == 1;
2184+
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
2185+
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
21962186

2197-
if flat_map_args.len() == 2;
2187+
if path.segments.len() == 1;
2188+
if path.segments[0].ident.as_str() == binding_ident.as_str();
21982189

2199-
let expr = &flat_map_args[1];
2190+
then {
2191+
let msg = "called `flat_map(|x| x)` on an `Iterator`. \
2192+
This can be simplified by calling `flatten().`";
2193+
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
2194+
}
2195+
}
22002196

2201-
if let hir::ExprKind::Path(ref qpath) = expr.node;
2197+
if_chain! {
2198+
let expr = &flat_map_args[1];
22022199

2203-
if match_qpath(qpath, &paths::STD_CONVERT_IDENTITY);
2200+
if let hir::ExprKind::Path(ref qpath) = expr.node;
22042201

2205-
then {
2206-
let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
2207-
This can be simplified by calling `flatten().`";
2208-
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
2202+
if match_qpath(qpath, &paths::STD_CONVERT_IDENTITY);
2203+
2204+
then {
2205+
let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
2206+
This can be simplified by calling `flatten().`";
2207+
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
2208+
}
2209+
}
22092210
}
22102211
}
22112212
}

0 commit comments

Comments
 (0)