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