@@ -46,21 +46,17 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy
4646 }
4747}
4848
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 {
5450 is_method ( cx, map_arg, sym:: unwrap) && is_method ( cx, filter_arg, sym ! ( is_some) )
5551}
5652
5753/// 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 < ' _ > ,
6460 target_span : Span ,
6561 methods_span : Span ,
6662) {
@@ -86,14 +82,28 @@ fn lint_filter_some_map_unwrap<'tcx>(
8682}
8783
8884/// 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+ ) ;
90106 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! {
97107 if is_trait_method( cx, map_recv, sym:: Iterator ) ;
98108
99109 // filter(|x| ...is_some())...
@@ -148,7 +158,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_
148158 } ;
149159 if SpanlessEq :: new( cx) . expr_fallback( eq_fallback) . eq_expr( filter_arg, map_arg) ;
150160 then {
151- let span = filter_span. to ( map_span ) ;
161+ let span = filter_span. with_hi ( expr . span . hi ( ) ) ;
152162 let ( filter_name, lint) = if is_find {
153163 ( "find" , MANUAL_FIND_MAP )
154164 } else {
@@ -160,7 +170,5 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_
160170 snippet( cx, map_arg. span, ".." ) , to_opt) ;
161171 span_lint_and_sugg( cx, lint, span, & msg, "try" , sugg, Applicability :: MachineApplicable ) ;
162172 }
163- }
164- }
165173 }
166174}
0 commit comments