|
1 |
| -use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; |
2 |
| -use crate::rustc::lint::LateContext; |
3 | 1 | use crate::rustc::hir;
|
4 | 2 | use crate::rustc::hir::def::Def;
|
| 3 | +use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; |
| 4 | +use crate::rustc::lint::LateContext; |
5 | 5 | use crate::syntax::ast;
|
6 |
| -use crate::utils::{match_qpath, match_trait_method, span_lint}; |
7 | 6 | use crate::utils::paths;
|
8 | 7 | use crate::utils::usage::mutated_variables;
|
| 8 | +use crate::utils::{match_qpath, match_trait_method, span_lint}; |
9 | 9 |
|
10 | 10 | use if_chain::if_chain;
|
11 | 11 |
|
12 | 12 | use super::UNNECESSARY_FILTER_MAP;
|
13 | 13 |
|
14 | 14 | pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
15 |
| - |
16 | 15 | if !match_trait_method(cx, expr, &paths::ITERATOR) {
|
17 | 16 | return;
|
18 | 17 | }
|
19 | 18 |
|
20 | 19 | if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
|
21 |
| - |
22 | 20 | let body = cx.tcx.hir.body(body_id);
|
23 | 21 | let arg_id = body.arguments[0].pat.id;
|
24 | 22 | let mutates_arg = match mutated_variables(&body.value, cx) {
|
25 |
| - Some(used_mutably) => used_mutably.contains(&arg_id), |
26 |
| - None => true, |
| 23 | + Some(used_mutably) => used_mutably.contains(&arg_id), |
| 24 | + None => true, |
27 | 25 | };
|
28 | 26 |
|
29 | 27 | let (mut found_mapping, mut found_filtering) = check_expression(&cx, arg_id, &body.value);
|
@@ -56,7 +54,11 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
|
56 | 54 | }
|
57 | 55 |
|
58 | 56 | // returns (found_mapping, found_filtering)
|
59 |
| -fn check_expression<'a, 'tcx: 'a>(cx: &'a LateContext<'a, 'tcx>, arg_id: ast::NodeId, expr: &'tcx hir::Expr) -> (bool, bool) { |
| 57 | +fn check_expression<'a, 'tcx: 'a>( |
| 58 | + cx: &'a LateContext<'a, 'tcx>, |
| 59 | + arg_id: ast::NodeId, |
| 60 | + expr: &'tcx hir::Expr, |
| 61 | +) -> (bool, bool) { |
60 | 62 | match &expr.node {
|
61 | 63 | hir::ExprKind::Call(ref func, ref args) => {
|
62 | 64 | if_chain! {
|
@@ -105,7 +107,7 @@ fn check_expression<'a, 'tcx: 'a>(cx: &'a LateContext<'a, 'tcx>, arg_id: ast::No
|
105 | 107 | (found_mapping, found_filtering)
|
106 | 108 | },
|
107 | 109 | hir::ExprKind::Path(path) if match_qpath(path, &paths::OPTION_NONE) => (false, true),
|
108 |
| - _ => (true, true) |
| 110 | + _ => (true, true), |
109 | 111 | }
|
110 | 112 | }
|
111 | 113 |
|
|
0 commit comments