@@ -7,7 +7,7 @@ use clippy_utils::{is_trait_method, path_to_local_id};
7
7
use if_chain:: if_chain;
8
8
use rustc_errors:: Applicability ;
9
9
use rustc_hir:: intravisit:: { walk_block, walk_expr, NestedVisitorMap , Visitor } ;
10
- use rustc_hir:: { Block , Expr , ExprKind , GenericArg , GenericArgs , HirId , PatKind , StmtKind , Ty } ;
10
+ use rustc_hir:: { Block , Expr , ExprKind , HirId , PatKind , StmtKind } ;
11
11
use rustc_lint:: LateContext ;
12
12
use rustc_middle:: hir:: map:: Map ;
13
13
use rustc_span:: sym;
@@ -24,10 +24,8 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
24
24
if let ExprKind :: MethodCall ( method, _, args, _) = expr. kind;
25
25
if let ExprKind :: MethodCall ( chain_method, method0_span, _, _) = args[ 0 ] . kind;
26
26
if chain_method. ident. name == sym!( collect) && is_trait_method( cx, & args[ 0 ] , sym:: Iterator ) ;
27
- if let Some ( generic_args) = chain_method. args;
28
- if let Some ( GenericArg :: Type ( ref ty) ) = generic_args. args. get( 0 ) ;
29
- if let Some ( ty) = cx. typeck_results( ) . node_type_opt( ty. hir_id) ;
30
27
then {
28
+ let ty = cx. typeck_results( ) . expr_ty( & args[ 0 ] ) ;
31
29
let mut applicability = Applicability :: MachineApplicable ;
32
30
let is_empty_sugg = "next().is_none()" . to_string( ) ;
33
31
let method_name = & * method. ident. name. as_str( ) ;
@@ -72,19 +70,6 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
72
70
}
73
71
74
72
fn check_needless_collect_indirect_usage < ' tcx > ( expr : & ' tcx Expr < ' _ > , cx : & LateContext < ' tcx > ) {
75
- fn get_hir_id < ' tcx > ( ty : Option < & Ty < ' tcx > > , method_args : Option < & GenericArgs < ' tcx > > ) -> Option < HirId > {
76
- if let Some ( ty) = ty {
77
- return Some ( ty. hir_id ) ;
78
- }
79
-
80
- if let Some ( generic_args) = method_args {
81
- if let Some ( GenericArg :: Type ( ref ty) ) = generic_args. args . get ( 0 ) {
82
- return Some ( ty. hir_id ) ;
83
- }
84
- }
85
-
86
- None
87
- }
88
73
if let ExprKind :: Block ( block, _) = expr. kind {
89
74
for stmt in block. stmts {
90
75
if_chain ! {
@@ -93,8 +78,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
93
78
if let Some ( init_expr) = local. init;
94
79
if let ExprKind :: MethodCall ( method_name, collect_span, & [ ref iter_source] , ..) = init_expr. kind;
95
80
if method_name. ident. name == sym!( collect) && is_trait_method( cx, init_expr, sym:: Iterator ) ;
96
- if let Some ( hir_id) = get_hir_id( local. ty, method_name. args) ;
97
- if let Some ( ty) = cx. typeck_results( ) . node_type_opt( hir_id) ;
81
+ let ty = cx. typeck_results( ) . expr_ty( init_expr) ;
98
82
if is_type_diagnostic_item( cx, ty, sym:: vec_type) ||
99
83
is_type_diagnostic_item( cx, ty, sym:: vecdeque_type) ||
100
84
is_type_diagnostic_item( cx, ty, sym:: BinaryHeap ) ||
0 commit comments