@@ -2172,42 +2172,37 @@ fn lint_flat_map_identity<'a, 'tcx>(
2172
2172
expr : & ' tcx hir:: Expr ,
2173
2173
flat_map_args : & ' tcx [ hir:: Expr ] ,
2174
2174
) {
2175
- if_chain ! {
2176
- if match_trait_method ( cx , expr , & paths :: ITERATOR ) ;
2175
+ if match_trait_method ( cx , expr , & paths :: ITERATOR ) {
2176
+ let arg_node = & flat_map_args [ 1 ] . node ;
2177
2177
2178
- if flat_map_args. len( ) == 2 ;
2178
+ let apply_lint = |message : & str | {
2179
+ span_lint ( cx, FLAT_MAP_IDENTITY , expr. span , message) ;
2180
+ } ;
2179
2181
2180
- then {
2181
- if_chain! {
2182
- if let hir:: ExprKind :: Closure ( _, _, body_id, _, _) = flat_map_args[ 1 ] . node;
2183
- let body = cx. tcx. hir( ) . body( body_id) ;
2182
+ if_chain ! {
2183
+ if let hir:: ExprKind :: Closure ( _, _, body_id, _, _) = arg_node;
2184
+ let body = cx. tcx. hir( ) . body( * body_id) ;
2184
2185
2185
- if body. arguments. len( ) == 1 ;
2186
- if let hir:: PatKind :: Binding ( _, _, binding_ident, _) = body. arguments[ 0 ] . pat. node;
2187
- if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = body. value. node;
2186
+ if let hir:: PatKind :: Binding ( _, _, binding_ident, _) = body. arguments[ 0 ] . pat. node;
2187
+ if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = body. value. node;
2188
2188
2189
- if path. segments. len( ) == 1 ;
2190
- if path. segments[ 0 ] . ident. as_str( ) == binding_ident. as_str( ) ;
2189
+ if path. segments. len( ) == 1 ;
2190
+ if path. segments[ 0 ] . ident. as_str( ) == binding_ident. as_str( ) ;
2191
2191
2192
- then {
2193
- let msg = "called `flat_map(|x| x)` on an `Iterator`. \
2194
- This can be simplified by calling `flatten().`";
2195
- span_lint( cx, FLAT_MAP_IDENTITY , expr. span, msg) ;
2196
- }
2192
+ then {
2193
+ apply_lint( "called `flat_map(|x| x)` on an `Iterator`. \
2194
+ This can be simplified by calling `flatten().`") ;
2197
2195
}
2196
+ }
2198
2197
2199
- if_chain! {
2200
- let expr = & flat_map_args[ 1 ] ;
2201
-
2202
- if let hir:: ExprKind :: Path ( ref qpath) = expr. node;
2198
+ if_chain ! {
2199
+ if let hir:: ExprKind :: Path ( ref qpath) = arg_node;
2203
2200
2204
- if match_qpath( qpath, & paths:: STD_CONVERT_IDENTITY ) ;
2201
+ if match_qpath( qpath, & paths:: STD_CONVERT_IDENTITY ) ;
2205
2202
2206
- then {
2207
- let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
2208
- This can be simplified by calling `flatten().`";
2209
- span_lint( cx, FLAT_MAP_IDENTITY , expr. span, msg) ;
2210
- }
2203
+ then {
2204
+ apply_lint( "called `flat_map(std::convert::identity)` on an `Iterator`. \
2205
+ This can be simplified by calling `flatten().`") ;
2211
2206
}
2212
2207
}
2213
2208
}
0 commit comments