@@ -46,21 +46,17 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy
46
46
}
47
47
}
48
48
49
- fn is_option_filter_map < ' tcx > (
50
- cx : & LateContext < ' tcx > ,
51
- filter_arg : & ' tcx hir:: Expr < ' _ > ,
52
- map_arg : & ' tcx hir:: Expr < ' _ > ,
53
- ) -> bool {
49
+ fn is_option_filter_map < ' tcx > ( cx : & LateContext < ' tcx > , filter_arg : & hir:: Expr < ' _ > , map_arg : & hir:: Expr < ' _ > ) -> bool {
54
50
is_method ( cx, map_arg, sym:: unwrap) && is_method ( cx, filter_arg, sym ! ( is_some) )
55
51
}
56
52
57
53
/// lint use of `filter().map()` for `Iterators`
58
- fn lint_filter_some_map_unwrap < ' tcx > (
59
- cx : & LateContext < ' tcx > ,
60
- expr : & ' tcx hir:: Expr < ' _ > ,
61
- filter_recv : & ' tcx hir:: Expr < ' _ > ,
62
- filter_arg : & ' tcx hir:: Expr < ' _ > ,
63
- map_arg : & ' tcx hir:: Expr < ' _ > ,
54
+ fn lint_filter_some_map_unwrap (
55
+ cx : & LateContext < ' _ > ,
56
+ expr : & hir:: Expr < ' _ > ,
57
+ filter_recv : & hir:: Expr < ' _ > ,
58
+ filter_arg : & hir:: Expr < ' _ > ,
59
+ map_arg : & hir:: Expr < ' _ > ,
64
60
target_span : Span ,
65
61
methods_span : Span ,
66
62
) {
@@ -86,14 +82,28 @@ fn lint_filter_some_map_unwrap<'tcx>(
86
82
}
87
83
88
84
/// lint use of `filter().map()` or `find().map()` for `Iterators`
89
- pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > , is_find : bool , target_span : Span ) {
85
+ #[ allow( clippy:: too_many_arguments) ]
86
+ pub ( super ) fn check < ' tcx > (
87
+ cx : & LateContext < ' tcx > ,
88
+ expr : & hir:: Expr < ' _ > ,
89
+ filter_recv : & hir:: Expr < ' _ > ,
90
+ filter_arg : & hir:: Expr < ' _ > ,
91
+ filter_span : Span ,
92
+ map_recv : & hir:: Expr < ' _ > ,
93
+ map_arg : & hir:: Expr < ' _ > ,
94
+ map_span : Span ,
95
+ is_find : bool ,
96
+ ) {
97
+ lint_filter_some_map_unwrap (
98
+ cx,
99
+ expr,
100
+ filter_recv,
101
+ filter_arg,
102
+ map_arg,
103
+ map_span,
104
+ filter_span. with_hi ( expr. span . hi ( ) ) ,
105
+ ) ;
90
106
if_chain ! {
91
- if let ExprKind :: MethodCall ( _, _, [ map_recv, map_arg] , map_span) = expr. kind;
92
- if let ExprKind :: MethodCall ( _, _, [ filter_recv, filter_arg] , filter_span) = map_recv. kind;
93
- then {
94
- lint_filter_some_map_unwrap( cx, expr, filter_recv, filter_arg,
95
- map_arg, target_span, filter_span. to( map_span) ) ;
96
- if_chain! {
97
107
if is_trait_method( cx, map_recv, sym:: Iterator ) ;
98
108
99
109
// filter(|x| ...is_some())...
@@ -148,7 +158,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_
148
158
} ;
149
159
if SpanlessEq :: new( cx) . expr_fallback( eq_fallback) . eq_expr( filter_arg, map_arg) ;
150
160
then {
151
- let span = filter_span. to ( map_span ) ;
161
+ let span = filter_span. with_hi ( expr . span . hi ( ) ) ;
152
162
let ( filter_name, lint) = if is_find {
153
163
( "find" , MANUAL_FIND_MAP )
154
164
} else {
@@ -160,7 +170,5 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_
160
170
snippet( cx, map_arg. span, ".." ) , to_opt) ;
161
171
span_lint_and_sugg( cx, lint, span, & msg, "try" , sugg, Applicability :: MachineApplicable ) ;
162
172
}
163
- }
164
- }
165
173
}
166
174
}
0 commit comments