@@ -2041,25 +2041,24 @@ fn check_manual_flatten<'tcx>(
2041
2041
& mut applicability,
2042
2042
) ;
2043
2043
// Determine if `arg` is by reference, an `Iterator`, or implicitly adjusted with `into_iter`
2044
- let hint = match arg. kind {
2045
- ExprKind :: AddrOf ( _, _, arg_expr) => {
2044
+ let arg_ty = cx. typeck_results( ) . expr_ty( arg) ;
2045
+ let hint = if arg_ty. is_ref( ) {
2046
+ if has_iter_method( cx, arg_ty) . is_none( ) {
2047
+ return ;
2048
+ } else if let ExprKind :: AddrOf ( _, _, arg_expr) = arg. kind {
2046
2049
format!( "{}.iter().flatten()" , snippet( cx, arg_expr. span, ".." ) )
2047
- } ,
2048
- ExprKind :: MethodCall ( _, _, _, _) | ExprKind :: Path ( QPath :: Resolved ( None , _) ) => {
2049
- // Determine if `arg` is `Iterator` or implicitly calls `into_iter`
2050
- let arg_ty = cx. typeck_results( ) . expr_ty( arg) ;
2051
- if let Some ( id) = get_trait_def_id( cx, & paths:: ITERATOR ) {
2052
- let is_iterator = implements_trait( cx, arg_ty, id, & [ ] ) ;
2053
- if is_iterator {
2054
- format!( "{}.flatten()" , arg_snippet)
2055
- } else {
2056
- format!( "{}.into_iter().flatten()" , arg_snippet)
2057
- }
2058
- } else {
2059
- return
2060
- }
2061
- } ,
2062
- _ => return ,
2050
+ } else {
2051
+ return ;
2052
+ }
2053
+ } else if let Some ( id) = get_trait_def_id( cx, & paths:: ITERATOR ) {
2054
+ let is_iterator = implements_trait( cx, arg_ty, id, & [ ] ) ;
2055
+ if is_iterator {
2056
+ format!( "{}.flatten()" , arg_snippet)
2057
+ } else {
2058
+ format!( "{}.into_iter().flatten()" , arg_snippet)
2059
+ }
2060
+ } else {
2061
+ return
2063
2062
} ;
2064
2063
2065
2064
span_lint_and_sugg(
0 commit comments