Skip to content

Commit 891e387

Browse files
Don't emit machine applicable map_flatten lint if there are code comments
1 parent b57d98b commit 891e387

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clippy_lints/src/methods/map_flatten.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::is_trait_method;
32
use clippy_utils::source::snippet_with_applicability;
43
use clippy_utils::ty::is_type_diagnostic_item;
4+
use clippy_utils::{is_trait_method, span_contains_comment};
55
use rustc_errors::Applicability;
66
use rustc_hir::Expr;
77
use rustc_lint::LateContext;
@@ -17,10 +17,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_
1717
let mut applicability = Applicability::MachineApplicable;
1818

1919
let closure_snippet = snippet_with_applicability(cx, map_arg.span, "..", &mut applicability);
20+
let span = expr.span.with_lo(map_span.lo());
21+
// If the methods are separated with comments, we don't apply suggestion automatically.
22+
if span_contains_comment(cx.tcx.sess.source_map(), span) {
23+
applicability = Applicability::Unspecified;
24+
}
2025
span_lint_and_sugg(
2126
cx,
2227
MAP_FLATTEN,
23-
expr.span.with_lo(map_span.lo()),
28+
span,
2429
format!("called `map(..).flatten()` on `{caller_ty_name}`"),
2530
format!("try replacing `map` with `{method_to_use}` and remove the `.flatten()`"),
2631
format!("{method_to_use}({closure_snippet})"),

0 commit comments

Comments
 (0)