Skip to content

Commit

Permalink
Only span notes if snippet is not multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Apr 30, 2019
1 parent a262806 commit ca903ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
20 changes: 12 additions & 8 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,14 +1965,18 @@ fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::E
let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
`.find_map(p)` instead.";
let filter_snippet = snippet(cx, filter_args[1].span, "..");
span_note_and_lint(
cx,
FILTER_MAP_NEXT,
expr.span,
msg,
expr.span,
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
);
if filter_snippet.lines().count() <= 1 {
span_note_and_lint(
cx,
FILTER_MAP_NEXT,
expr.span,
msg,
expr.span,
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
);
} else {
span_lint(cx, FILTER_MAP_NEXT, expr.span, msg);
}
}
}

Expand Down
14 changes: 0 additions & 14 deletions tests/ui/filter_map_next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ LL | | if x == 2 {
LL | | })
LL | | .next();
| |_______________^
|
= note: replace `filter_map(|x| {
if x == 2 {
Some(x * 2)
} else {
None
}
}).next()` with `find_map(|x| {
if x == 2 {
Some(x * 2)
} else {
None
}
})`

error: aborting due to 2 previous errors

0 comments on commit ca903ac

Please sign in to comment.