@@ -3,9 +3,9 @@ use crate::utils::{
3
3
} ;
4
4
use if_chain:: if_chain;
5
5
use rustc_errors:: Applicability ;
6
- use rustc_lint:: { LateLintPass , LateContext } ;
6
+ use rustc_hir:: { def, Body , Expr , ExprKind , Pat , PatKind , Path , QPath , StmtKind } ;
7
+ use rustc_lint:: { LateContext , LateLintPass } ;
7
8
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
8
- use rustc_hir:: { Body , Expr , ExprKind , Pat , PatKind , Path , QPath , StmtKind , def} ;
9
9
10
10
declare_clippy_lint ! {
11
11
/// **What it does:** Checks for instances of `map(f)` where `f` is the identity function.
@@ -57,15 +57,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapIdentity {
57
57
}
58
58
}
59
59
60
-
61
60
/// Returns the arguments passed into map() if the expression is a method call to
62
61
/// map(). Otherwise, returns None.
63
62
fn get_map_argument < ' a > ( cx : & LateContext < ' _ , ' _ > , expr : & ' a Expr < ' a > ) -> Option < & ' a [ Expr < ' a > ] > {
64
63
if_chain ! {
65
64
if let ExprKind :: MethodCall ( ref method, _, ref args) = expr. kind;
66
65
if args. len( ) == 2 && method. ident. as_str( ) == "map" ;
67
66
let caller_ty = cx. tables. expr_ty( & args[ 0 ] ) ;
68
- if match_trait_method( cx, expr, & paths:: ITERATOR )
67
+ if match_trait_method( cx, expr, & paths:: ITERATOR )
69
68
|| is_type_diagnostic_item( cx, caller_ty, sym!( result_type) )
70
69
|| is_type_diagnostic_item( cx, caller_ty, sym!( option_type) ) ;
71
70
then {
@@ -100,8 +99,8 @@ fn is_identity_function(cx: &LateContext<'_, '_>, func: &Body<'_>) -> bool {
100
99
false
101
100
}
102
101
}
103
- }
104
- _ => false
102
+ } ,
103
+ _ => false ,
105
104
}
106
105
}
107
106
@@ -110,14 +109,15 @@ fn get_body<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'a>) -> Option<&'a Body
110
109
match expr. kind {
111
110
ExprKind :: Closure ( _, _, body_id, _, _) => Some ( cx. tcx . hir ( ) . body ( body_id) ) ,
112
111
ExprKind :: Path ( QPath :: Resolved ( _, ref path) ) => path_to_body ( cx, path) ,
113
- _ => None
112
+ _ => None ,
114
113
}
115
114
}
116
115
117
116
/// Returns the function body associated with a path
118
117
fn path_to_body < ' a > ( cx : & LateContext < ' a , ' _ > , path : & ' a Path < ' a > ) -> Option < & ' a Body < ' a > > {
119
118
if let def:: Res :: Def ( _, def_id) = path. res {
120
- def_id. as_local ( )
119
+ def_id
120
+ . as_local ( )
121
121
. and_then ( |local_id| cx. tcx . hir ( ) . opt_local_def_id_to_hir_id ( local_id) )
122
122
. and_then ( |hir_id| cx. tcx . hir ( ) . maybe_body_owned_by ( hir_id) )
123
123
. map ( |body_id| cx. tcx . hir ( ) . body ( body_id) )
0 commit comments