Skip to content

Commit 018e0e2

Browse files
committed
make the spans more precise
1 parent 54e3e3b commit 018e0e2

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,13 +5162,13 @@ impl Methods {
51625162
},
51635163
(sym::filter_map, [arg]) => {
51645164
unused_enumerate_index::check(cx, expr, recv, arg);
5165-
unnecessary_filter_map::check(cx, expr, arg, unnecessary_filter_map::Kind::FilterMap);
5165+
unnecessary_filter_map::check(cx, expr, arg, call_span, unnecessary_filter_map::Kind::FilterMap);
51665166
filter_map_bool_then::check(cx, expr, arg, call_span);
51675167
filter_map_identity::check(cx, expr, arg, span);
51685168
},
51695169
(sym::find_map, [arg]) => {
51705170
unused_enumerate_index::check(cx, expr, recv, arg);
5171-
unnecessary_filter_map::check(cx, expr, arg, unnecessary_filter_map::Kind::FindMap);
5171+
unnecessary_filter_map::check(cx, expr, arg, call_span, unnecessary_filter_map::Kind::FindMap);
51725172
},
51735173
(sym::flat_map, [arg]) => {
51745174
unused_enumerate_index::check(cx, expr, recv, arg);

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ use core::ops::ControlFlow;
99
use rustc_hir as hir;
1010
use rustc_hir::LangItem::{OptionNone, OptionSome};
1111
use rustc_lint::LateContext;
12+
use rustc_span::Span;
1213
use std::fmt::Display;
1314

1415
use super::{UNNECESSARY_FILTER_MAP, UNNECESSARY_FIND_MAP};
1516

16-
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>, kind: Kind) {
17+
pub(super) fn check<'tcx>(
18+
cx: &LateContext<'tcx>,
19+
expr: &'tcx hir::Expr<'tcx>,
20+
arg: &'tcx hir::Expr<'tcx>,
21+
call_span: Span,
22+
kind: Kind,
23+
) {
1724
if !cx.ty_based_def(expr).opt_parent(cx).is_diag_item(cx, sym::Iterator) {
1825
return;
1926
}
@@ -47,7 +54,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
4754
span_lint(
4855
cx,
4956
UNNECESSARY_FILTER_MAP,
50-
expr.span,
57+
call_span,
5158
String::from("this call to `.filter_map(..)` is unnecessary"),
5259
);
5360
return;
@@ -75,7 +82,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
7582
Kind::FilterMap => UNNECESSARY_FILTER_MAP,
7683
Kind::FindMap => UNNECESSARY_FIND_MAP,
7784
},
78-
expr.span,
85+
call_span,
7986
format!("this `.{kind}(..)` can be written more simply using `.{sugg}`"),
8087
);
8188
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
2-
--> tests/ui/unnecessary_filter_map.rs:4:13
2+
--> tests/ui/unnecessary_filter_map.rs:4:20
33
|
44
LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None });
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::unnecessary-filter-map` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]`
99

1010
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
11-
--> tests/ui/unnecessary_filter_map.rs:7:13
11+
--> tests/ui/unnecessary_filter_map.rs:7:20
1212
|
1313
LL | let _ = (0..4).filter_map(|x| {
14-
| _____________^
14+
| ____________________^
1515
LL | |
1616
LL | |
1717
LL | | if x > 1 {
@@ -21,33 +21,33 @@ LL | | });
2121
| |______^
2222

2323
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
24-
--> tests/ui/unnecessary_filter_map.rs:15:13
24+
--> tests/ui/unnecessary_filter_map.rs:15:20
2525
|
2626
LL | let _ = (0..4).filter_map(|x| match x {
27-
| _____________^
27+
| ____________________^
2828
LL | |
2929
LL | | 0 | 1 => None,
3030
LL | | _ => Some(x),
3131
LL | | });
3232
| |______^
3333

3434
error: this `.filter_map(..)` can be written more simply using `.map(..)`
35-
--> tests/ui/unnecessary_filter_map.rs:21:13
35+
--> tests/ui/unnecessary_filter_map.rs:21:20
3636
|
3737
LL | let _ = (0..4).filter_map(|x| Some(x + 1));
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: this call to `.filter_map(..)` is unnecessary
41-
--> tests/ui/unnecessary_filter_map.rs:28:61
41+
--> tests/ui/unnecessary_filter_map.rs:28:46
4242
|
4343
LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x));
44-
| ^^^^
44+
| ^^^^^^^^^^^^^^^^^^^^^^^
4545

4646
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
47-
--> tests/ui/unnecessary_filter_map.rs:166:14
47+
--> tests/ui/unnecessary_filter_map.rs:166:33
4848
|
4949
LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
error: aborting due to 6 previous errors
5353

tests/ui/unnecessary_find_map.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(dead_code)]
2-
31
fn main() {
42
let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
53
//~^ unnecessary_find_map
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: this `.find_map(..)` can be written more simply using `.find(..)`
2-
--> tests/ui/unnecessary_find_map.rs:4:13
2+
--> tests/ui/unnecessary_find_map.rs:2:20
33
|
44
LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::unnecessary-find-map` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]`
99

1010
error: this `.find_map(..)` can be written more simply using `.find(..)`
11-
--> tests/ui/unnecessary_find_map.rs:7:13
11+
--> tests/ui/unnecessary_find_map.rs:5:20
1212
|
1313
LL | let _ = (0..4).find_map(|x| {
14-
| _____________^
14+
| ____________________^
1515
LL | |
1616
LL | |
1717
LL | | if x > 1 {
@@ -21,27 +21,27 @@ LL | | });
2121
| |______^
2222

2323
error: this `.find_map(..)` can be written more simply using `.find(..)`
24-
--> tests/ui/unnecessary_find_map.rs:15:13
24+
--> tests/ui/unnecessary_find_map.rs:13:20
2525
|
2626
LL | let _ = (0..4).find_map(|x| match x {
27-
| _____________^
27+
| ____________________^
2828
LL | |
2929
LL | | 0 | 1 => None,
3030
LL | | _ => Some(x),
3131
LL | | });
3232
| |______^
3333

3434
error: this `.find_map(..)` can be written more simply using `.map(..).next()`
35-
--> tests/ui/unnecessary_find_map.rs:21:13
35+
--> tests/ui/unnecessary_find_map.rs:19:20
3636
|
3737
LL | let _ = (0..4).find_map(|x| Some(x + 1));
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: this `.find_map(..)` can be written more simply using `.find(..)`
41-
--> tests/ui/unnecessary_find_map.rs:33:14
41+
--> tests/ui/unnecessary_find_map.rs:31:33
4242
|
4343
LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545

4646
error: aborting due to 5 previous errors
4747

0 commit comments

Comments
 (0)