Skip to content

Commit ca903ac

Browse files
committed
Only span notes if snippet is not multiline
1 parent a262806 commit ca903ac

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,14 +1965,18 @@ fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::E
19651965
let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
19661966
`.find_map(p)` instead.";
19671967
let filter_snippet = snippet(cx, filter_args[1].span, "..");
1968-
span_note_and_lint(
1969-
cx,
1970-
FILTER_MAP_NEXT,
1971-
expr.span,
1972-
msg,
1973-
expr.span,
1974-
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
1975-
);
1968+
if filter_snippet.lines().count() <= 1 {
1969+
span_note_and_lint(
1970+
cx,
1971+
FILTER_MAP_NEXT,
1972+
expr.span,
1973+
msg,
1974+
expr.span,
1975+
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
1976+
);
1977+
} else {
1978+
span_lint(cx, FILTER_MAP_NEXT, expr.span, msg);
1979+
}
19761980
}
19771981
}
19781982

tests/ui/filter_map_next.stderr

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ LL | | if x == 2 {
1919
LL | | })
2020
LL | | .next();
2121
| |_______________^
22-
|
23-
= note: replace `filter_map(|x| {
24-
if x == 2 {
25-
Some(x * 2)
26-
} else {
27-
None
28-
}
29-
}).next()` with `find_map(|x| {
30-
if x == 2 {
31-
Some(x * 2)
32-
} else {
33-
None
34-
}
35-
})`
3622

3723
error: aborting due to 2 previous errors
3824

0 commit comments

Comments
 (0)