@@ -3,6 +3,7 @@ use clippy_utils::source::snippet_with_macro_callsite;
3
3
use clippy_utils:: visitors:: for_each_value_source;
4
4
use core:: ops:: ControlFlow ;
5
5
use rustc_errors:: Applicability ;
6
+ use rustc_hir:: def:: { DefKind , Res } ;
6
7
use rustc_hir:: { Expr , ExprKind , PatKind , Stmt , StmtKind } ;
7
8
use rustc_lint:: { LateContext , LintContext } ;
8
9
use rustc_middle:: lint:: in_external_macro;
@@ -71,14 +72,18 @@ fn needs_inferred_result_ty(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
71
72
..
72
73
} ,
73
74
_,
74
- ) => cx. qpath_res ( path, * hir_id) . opt_def_id ( ) ,
75
- ExprKind :: MethodCall ( ..) => cx. typeck_results ( ) . type_dependent_def_id ( e. hir_id ) ,
75
+ ) => match cx. qpath_res ( path, * hir_id) {
76
+ Res :: Def ( DefKind :: AssocFn | DefKind :: Fn , id) => id,
77
+ _ => return false ,
78
+ } ,
79
+ ExprKind :: MethodCall ( ..) => match cx. typeck_results ( ) . type_dependent_def_id ( e. hir_id ) {
80
+ Some ( id) => id,
81
+ None => return false ,
82
+ } ,
76
83
_ => return false ,
77
84
} ;
78
- if let Some ( id) = id
79
- && let sig = cx. tcx . fn_sig ( id) . skip_binder ( )
80
- && let ty:: Param ( output_ty) = * sig. output ( ) . kind ( )
81
- {
85
+ let sig = cx. tcx . fn_sig ( id) . skip_binder ( ) ;
86
+ if let ty:: Param ( output_ty) = * sig. output ( ) . kind ( ) {
82
87
sig. inputs ( ) . iter ( ) . all ( |& ty| !ty_contains_param ( ty, output_ty. index ) )
83
88
} else {
84
89
false
0 commit comments