@@ -503,7 +503,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
503
503
}
504
504
505
505
fn check_pat ( & mut self , cx : & LateContext < ' tcx > , pat : & ' tcx Pat < ' _ > ) {
506
- if let PatKind :: Binding ( BindingAnnotation :: Ref , id, name, _) = pat. kind {
506
+ if let PatKind :: Binding ( BindingAnnotation :: REF , id, name, _) = pat. kind {
507
507
if let Some ( opt_prev_pat) = self . ref_locals . get_mut ( & id) {
508
508
// This binding id has been seen before. Add this pattern to the list of changes.
509
509
if let Some ( prev_pat) = opt_prev_pat {
@@ -581,7 +581,7 @@ fn try_parse_ref_op<'tcx>(
581
581
expr : & ' tcx Expr < ' _ > ,
582
582
) -> Option < ( RefOp , & ' tcx Expr < ' tcx > ) > {
583
583
let ( def_id, arg) = match expr. kind {
584
- ExprKind :: MethodCall ( _, [ arg] , _) => ( typeck. type_dependent_def_id ( expr. hir_id ) ?, arg) ,
584
+ ExprKind :: MethodCall ( _, arg, [ ] , _) => ( typeck. type_dependent_def_id ( expr. hir_id ) ?, arg) ,
585
585
ExprKind :: Call (
586
586
Expr {
587
587
kind : ExprKind :: Path ( path) ,
@@ -796,56 +796,54 @@ fn walk_parents<'tcx>(
796
796
} ,
797
797
} )
798
798
} ) ,
799
- ExprKind :: MethodCall ( _, args, _) => {
799
+ ExprKind :: MethodCall ( _, receiver , args, _) => {
800
800
let id = cx. typeck_results ( ) . type_dependent_def_id ( parent. hir_id ) . unwrap ( ) ;
801
- args. iter ( ) . position ( |arg| arg. hir_id == child_id) . map ( |i| {
802
- if i == 0 {
803
- // Check for calls to trait methods where the trait is implemented on a reference.
804
- // Two cases need to be handled:
805
- // * `self` methods on `&T` will never have auto-borrow
806
- // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
807
- // priority.
808
- if e. hir_id != child_id {
809
- Position :: ReborrowStable ( precedence)
810
- } else if let Some ( trait_id) = cx. tcx . trait_of_item ( id)
811
- && let arg_ty = cx. tcx . erase_regions ( cx. typeck_results ( ) . expr_ty_adjusted ( e) )
812
- && let ty:: Ref ( _, sub_ty, _) = * arg_ty. kind ( )
813
- && let subs = match cx
814
- . typeck_results ( )
815
- . node_substs_opt ( parent. hir_id )
816
- . and_then ( |subs| subs. get ( 1 ..) )
817
- {
818
- Some ( subs) => cx. tcx . mk_substs ( subs. iter ( ) . copied ( ) ) ,
819
- None => cx. tcx . mk_substs ( std:: iter:: empty :: < ty:: subst:: GenericArg < ' _ > > ( ) ) ,
820
- } && let impl_ty = if cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ 0 ] . is_ref ( ) {
821
- // Trait methods taking `&self`
822
- sub_ty
823
- } else {
824
- // Trait methods taking `self`
825
- arg_ty
826
- } && impl_ty. is_ref ( )
827
- && cx. tcx . infer_ctxt ( ) . enter ( |infcx|
828
- infcx
829
- . type_implements_trait ( trait_id, impl_ty, subs, cx. param_env )
830
- . must_apply_modulo_regions ( )
831
- )
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 ..) )
832
816
{
833
- 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
834
822
} else {
835
- Position :: MethodReceiver
836
- }
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
+ }
834
+ return Some ( Position :: MethodReceiver ) ;
835
+ }
836
+ args. iter ( ) . position ( |arg| arg. hir_id == child_id) . map ( |i| {
837
+ let ty = cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ i + 1 ] ;
838
+ if let ty:: Param ( param_ty) = ty. kind ( ) {
839
+ needless_borrow_impl_arg_position ( cx, parent, i + 1 , * param_ty, e, precedence, msrv)
837
840
} else {
838
- let ty = cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ i] ;
839
- if let ty:: Param ( param_ty) = ty. kind ( ) {
840
- needless_borrow_impl_arg_position ( cx, parent, i, * param_ty, e, precedence, msrv)
841
- } else {
842
- ty_auto_deref_stability (
843
- cx,
844
- cx. tcx . erase_late_bound_regions ( cx. tcx . fn_sig ( id) . input ( i) ) ,
845
- precedence,
846
- )
847
- . position_for_arg ( )
848
- }
841
+ ty_auto_deref_stability (
842
+ cx,
843
+ cx. tcx . erase_late_bound_regions ( cx. tcx . fn_sig ( id) . input ( i + 1 ) ) ,
844
+ precedence,
845
+ )
846
+ . position_for_arg ( )
849
847
}
850
848
} )
851
849
} ,
@@ -1174,7 +1172,7 @@ fn replace_types<'tcx>(
1174
1172
if replaced. insert ( param_ty. index ) {
1175
1173
for projection_predicate in projection_predicates {
1176
1174
if projection_predicate. projection_ty . self_ty ( ) == param_ty. to_ty ( cx. tcx )
1177
- && let ty :: Term :: Ty ( term_ty) = projection_predicate. term
1175
+ && let Some ( term_ty) = projection_predicate. term . ty ( )
1178
1176
&& let ty:: Param ( term_param_ty) = term_ty. kind ( )
1179
1177
{
1180
1178
let item_def_id = projection_predicate. projection_ty . item_def_id ;
0 commit comments