@@ -798,57 +798,55 @@ fn walk_parents<'tcx>(
798
798
} ) ,
799
799
ExprKind :: MethodCall ( _, receiver, args, _) => {
800
800
let id = cx. typeck_results ( ) . type_dependent_def_id ( parent. hir_id ) . unwrap ( ) ;
801
- std:: iter:: once ( receiver)
802
- . chain ( args. iter ( ) )
803
- . position ( |arg| arg. hir_id == child_id)
804
- . map ( |i| {
805
- if i == 0 {
806
- // Check for calls to trait methods where the trait is implemented on a reference.
807
- // Two cases need to be handled:
808
- // * `self` methods on `&T` will never have auto-borrow
809
- // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
810
- // priority.
811
- if e. hir_id != child_id {
812
- Position :: ReborrowStable ( precedence)
813
- } else if let Some ( trait_id) = cx. tcx . trait_of_item ( id)
814
- && let arg_ty = cx. tcx . erase_regions ( cx. typeck_results ( ) . expr_ty_adjusted ( e) )
815
- && let ty:: Ref ( _, sub_ty, _) = * arg_ty. kind ( )
816
- && let subs = match cx
817
- . typeck_results ( )
818
- . node_substs_opt ( parent. hir_id )
819
- . and_then ( |subs| subs. get ( 1 ..) )
820
- {
821
- Some ( subs) => cx. tcx . mk_substs ( subs. iter ( ) . copied ( ) ) ,
822
- None => cx. tcx . mk_substs ( std:: iter:: empty :: < ty:: subst:: GenericArg < ' _ > > ( ) ) ,
823
- } && let impl_ty = if cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ 0 ] . is_ref ( ) {
824
- // Trait methods taking `&self`
825
- sub_ty
826
- } else {
827
- // Trait methods taking `self`
828
- arg_ty
829
- } && impl_ty. is_ref ( )
830
- && cx. tcx . infer_ctxt ( ) . enter ( |infcx|
831
- infcx
832
- . type_implements_trait ( trait_id, impl_ty, subs, cx. param_env )
833
- . must_apply_modulo_regions ( )
834
- )
801
+ if receiver. hir_id == child_id {
802
+ // Check for calls to trait methods where the trait is implemented on a reference.
803
+ // Two cases need to be handled:
804
+ // * `self` methods on `&T` will never have auto-borrow
805
+ // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
806
+ // priority.
807
+ if e. hir_id != child_id {
808
+ return Some ( Position :: ReborrowStable ( precedence) )
809
+ } else if let Some ( trait_id) = cx. tcx . trait_of_item ( id)
810
+ && let arg_ty = cx. tcx . erase_regions ( cx. typeck_results ( ) . expr_ty_adjusted ( e) )
811
+ && let ty:: Ref ( _, sub_ty, _) = * arg_ty. kind ( )
812
+ && let subs = match cx
813
+ . typeck_results ( )
814
+ . node_substs_opt ( parent. hir_id )
815
+ . and_then ( |subs| subs. get ( 1 ..) )
835
816
{
836
- Position :: MethodReceiverRefImpl
817
+ Some ( subs) => cx. tcx . mk_substs ( subs. iter ( ) . copied ( ) ) ,
818
+ None => cx. tcx . mk_substs ( std:: iter:: empty :: < ty:: subst:: GenericArg < ' _ > > ( ) ) ,
819
+ } && let impl_ty = if cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ 0 ] . is_ref ( ) {
820
+ // Trait methods taking `&self`
821
+ sub_ty
837
822
} else {
838
- Position :: MethodReceiver
839
- }
823
+ // Trait methods taking `self`
824
+ arg_ty
825
+ } && impl_ty. is_ref ( )
826
+ && cx. tcx . infer_ctxt ( ) . enter ( |infcx|
827
+ infcx
828
+ . type_implements_trait ( trait_id, impl_ty, subs, cx. param_env )
829
+ . must_apply_modulo_regions ( )
830
+ )
831
+ {
832
+ return Some ( Position :: MethodReceiverRefImpl )
833
+ } else {
834
+ return Some ( Position :: MethodReceiver )
835
+ }
836
+ }
837
+ args. iter ( )
838
+ . position ( |arg| arg. hir_id == child_id)
839
+ . map ( |i| {
840
+ let ty = cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ i + 1 ] ;
841
+ if let ty:: Param ( param_ty) = ty. kind ( ) {
842
+ needless_borrow_impl_arg_position ( cx, parent, i + 1 , * param_ty, e, precedence, msrv)
840
843
} else {
841
- let ty = cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ i] ;
842
- if let ty:: Param ( param_ty) = ty. kind ( ) {
843
- needless_borrow_impl_arg_position ( cx, parent, i, * param_ty, e, precedence, msrv)
844
- } else {
845
- ty_auto_deref_stability (
846
- cx,
847
- cx. tcx . erase_late_bound_regions ( cx. tcx . fn_sig ( id) . input ( i) ) ,
848
- precedence,
849
- )
850
- . position_for_arg ( )
851
- }
844
+ ty_auto_deref_stability (
845
+ cx,
846
+ cx. tcx . erase_late_bound_regions ( cx. tcx . fn_sig ( id) . input ( i + 1 ) ) ,
847
+ precedence,
848
+ )
849
+ . position_for_arg ( )
852
850
}
853
851
} )
854
852
} ,
0 commit comments