@@ -3,6 +3,7 @@ use clippy_utils::source::snippet_with_macro_callsite;
33use clippy_utils:: visitors:: for_each_value_source;
44use core:: ops:: ControlFlow ;
55use rustc_errors:: Applicability ;
6+ use rustc_hir:: def:: { DefKind , Res } ;
67use rustc_hir:: { Expr , ExprKind , PatKind , Stmt , StmtKind } ;
78use rustc_lint:: { LateContext , LintContext } ;
89use rustc_middle:: lint:: in_external_macro;
@@ -71,14 +72,18 @@ fn needs_inferred_result_ty(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
7172 ..
7273 } ,
7374 _,
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+ } ,
7683 _ => return false ,
7784 } ;
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 ( ) {
8287 sig. inputs ( ) . iter ( ) . all ( |& ty| !ty_contains_param ( ty, output_ty. index ) )
8388 } else {
8489 false
0 commit comments