@@ -805,30 +805,39 @@ fn walk_parents<'tcx>(
805805 . position ( |arg| arg. hir_id == child_id)
806806 . zip ( expr_sig ( cx, func) )
807807 . and_then ( |( i, sig) | {
808- sig. input_with_hir ( i) . map ( |( hir_ty, ty) | match hir_ty {
809- // Type inference for closures can depend on how they're called. Only go by the explicit
810- // types here.
811- Some ( hir_ty) => binding_ty_auto_deref_stability ( cx, hir_ty, precedence, ty. bound_vars ( ) ) ,
812- None => {
813- if let ty:: Param ( param_ty) = ty. skip_binder ( ) . kind ( ) {
814- needless_borrow_impl_arg_position (
815- cx,
816- possible_borrowers,
817- parent,
818- i,
819- * param_ty,
820- e,
821- precedence,
822- msrv,
823- )
824- } else {
825- ty_auto_deref_stability ( cx, cx. tcx . erase_late_bound_regions ( ty) , precedence)
826- . position_for_arg ( )
827- }
828- } ,
808+ sig. input_with_hir ( i) . map ( |( hir_ty, ty) | {
809+ match hir_ty {
810+ // Type inference for closures can depend on how they're called. Only go by the explicit
811+ // types here.
812+ Some ( hir_ty) => {
813+ binding_ty_auto_deref_stability ( cx, hir_ty, precedence, ty. bound_vars ( ) )
814+ } ,
815+ None => {
816+ // `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739
817+ // `!call_is_qualified(func)` for https://github.com/rust-lang/rust-clippy/issues/9782
818+ if e. hir_id == child_id
819+ && !call_is_qualified ( func)
820+ && let ty:: Param ( param_ty) = ty. skip_binder ( ) . kind ( )
821+ {
822+ needless_borrow_impl_arg_position (
823+ cx,
824+ possible_borrowers,
825+ parent,
826+ i,
827+ * param_ty,
828+ e,
829+ precedence,
830+ msrv,
831+ )
832+ } else {
833+ ty_auto_deref_stability ( cx, cx. tcx . erase_late_bound_regions ( ty) , precedence)
834+ . position_for_arg ( )
835+ }
836+ } ,
837+ }
829838 } )
830839 } ) ,
831- ExprKind :: MethodCall ( _ , receiver, args, _) => {
840+ ExprKind :: MethodCall ( method , receiver, args, _) => {
832841 let id = cx. typeck_results ( ) . type_dependent_def_id ( parent. hir_id ) . unwrap ( ) ;
833842 if receiver. hir_id == child_id {
834843 // Check for calls to trait methods where the trait is implemented on a reference.
@@ -866,7 +875,9 @@ fn walk_parents<'tcx>(
866875 }
867876 args. iter ( ) . position ( |arg| arg. hir_id == child_id) . map ( |i| {
868877 let ty = cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ i + 1 ] ;
869- if let ty:: Param ( param_ty) = ty. kind ( ) {
878+ // `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739
879+ // `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782
880+ if e. hir_id == child_id && method. args . is_none ( ) && let ty:: Param ( param_ty) = ty. kind ( ) {
870881 needless_borrow_impl_arg_position (
871882 cx,
872883 possible_borrowers,
@@ -1044,6 +1055,18 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool {
10441055 v. 0
10451056}
10461057
1058+ fn call_is_qualified ( expr : & Expr < ' _ > ) -> bool {
1059+ if let ExprKind :: Path ( path) = & expr. kind {
1060+ match path {
1061+ QPath :: Resolved ( _, path) => path. segments . last ( ) . map_or ( false , |segment| segment. args . is_some ( ) ) ,
1062+ QPath :: TypeRelative ( _, segment) => segment. args . is_some ( ) ,
1063+ QPath :: LangItem ( ..) => false ,
1064+ }
1065+ } else {
1066+ false
1067+ }
1068+ }
1069+
10471070// Checks whether:
10481071// * child is an expression of the form `&e` in an argument position requiring an `impl Trait`
10491072// * `e`'s type implements `Trait` and is copyable
0 commit comments