Skip to content

Commit 2c837d7

Browse files
author
Eric Loren
committed
add current lint to middle of new one, get most tests passing
1 parent 42b362a commit 2c837d7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_ast::ast;
1818
use rustc_errors::Applicability;
1919
use rustc_hir as hir;
2020
use rustc_hir::def::Res;
21-
use rustc_hir::intravisit::{self, Visitor};
2221
use rustc_hir::{Expr, ExprKind, PatKind, TraitItem, TraitItemKind, UnOp};
2322
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
2423
use rustc_middle::lint::in_external_macro;
@@ -35,7 +34,7 @@ use crate::utils::usage::mutated_variables;
3534
use crate::utils::{
3635
contains_return, contains_ty, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait,
3736
in_macro, is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path,
38-
match_qpath, match_trait_method, match_type, match_var, meets_msrv, method_calls, method_chain_args,
37+
match_qpath, match_trait_method, match_type, meets_msrv, method_calls, method_chain_args,
3938
path_to_local_id, paths, remove_blocks, return_ty, single_segment_path, snippet, snippet_block,
4039
snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
4140
span_lint_and_then, strip_pat_refs, sugg, walk_ptrs_ty_depth, SpanlessEq,
@@ -3119,9 +3118,7 @@ fn lint_filter_map<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_f
31193118
if let ExprKind::MethodCall(_, _, [map_recv, map_arg], map_span) = expr.kind;
31203119
if let ExprKind::MethodCall(_, _, [filter_recv, filter_arg], filter_span) = map_recv.kind;
31213120
let _ = {
3122-
lint_filter_some_map_unwrap(cx, expr, filter_recv, filter_arg,
3123-
map_recv, map_arg, span);
3124-
1
3121+
lint_filter_some_map_unwrap(cx, expr, filter_recv, filter_arg, map_arg, span);
31253122
};
31263123
if match_trait_method(cx, map_recv, &paths::ITERATOR);
31273124

@@ -3240,7 +3237,6 @@ fn lint_filter_some_map_unwrap<'tcx>(
32403237
expr: &'tcx hir::Expr<'_>,
32413238
filter_recv: &'tcx hir::Expr<'_>,
32423239
filter_arg: &'tcx hir::Expr<'_>,
3243-
map_recv: &'tcx hir::Expr<'_>,
32443240
map_arg: &'tcx hir::Expr<'_>,
32453241
target_span: Span,
32463242
) {

tests/ui/filter_methods.stderr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
error: called `filter(..).map(..)` on an `Iterator`
2+
--> $DIR/filter_methods.rs:6:21
3+
|
4+
LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::filter-map` implied by `-D warnings`
8+
= help: this is more succinctly expressed by calling `.filter_map(..)` instead
9+
110
error: called `filter(..).flat_map(..)` on an `Iterator`
211
--> $DIR/filter_methods.rs:8:21
312
|
@@ -8,7 +17,6 @@ LL | | .filter(|&x| x == 0)
817
LL | | .flat_map(|x| x.checked_mul(2))
918
| |_______________________________________^
1019
|
11-
= note: `-D clippy::filter-map` implied by `-D warnings`
1220
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
1321

1422
error: called `filter_map(..).flat_map(..)` on an `Iterator`
@@ -35,5 +43,5 @@ LL | | .map(|x| x.checked_mul(2))
3543
|
3644
= help: this is more succinctly expressed by only calling `.filter_map(..)` instead
3745

38-
error: aborting due to 3 previous errors
46+
error: aborting due to 4 previous errors
3947

tests/ui/option_filter_map.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ LL | let _ = vec![1]
7171
LL | .into_iter()
7272
LL | .map(odds_out).flatten();
7373
|
74+
7475
error: aborting due to 8 previous errors
76+

0 commit comments

Comments
 (0)