@@ -6,7 +6,7 @@ use clippy_utils::source::snippet_with_applicability;
66use clippy_utils:: { is_lint_allowed, is_wild, span_contains_comment} ;
77use rustc_ast:: LitKind ;
88use rustc_errors:: Applicability ;
9- use rustc_hir:: { Arm , Attribute , BorrowKind , Expr , ExprKind , Pat , PatKind , QPath } ;
9+ use rustc_hir:: { Arm , BorrowKind , Expr , ExprKind , Pat , PatKind , QPath } ;
1010use rustc_lint:: { LateContext , LintContext } ;
1111use rustc_middle:: ty;
1212use rustc_span:: source_map:: Spanned ;
@@ -65,27 +65,12 @@ pub(super) fn check_match<'tcx>(
6565 scrutinee : & ' tcx Expr < ' _ > ,
6666 arms : & ' tcx [ Arm < ' tcx > ] ,
6767) -> bool {
68- find_matches_sugg (
69- cx,
70- scrutinee,
71- arms. iter ( )
72- . map ( |arm| ( cx. tcx . hir_attrs ( arm. hir_id ) , Some ( arm. pat ) , arm. body , arm. guard ) ) ,
73- e,
74- )
75- }
76-
77- /// Lint a `match` or `if let` for replacement by `matches!`
78- fn find_matches_sugg < ' a , ' b , I > ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > , mut arms : I , expr : & Expr < ' _ > ) -> bool
79- where
80- ' b : ' a ,
81- I : Clone
82- + DoubleEndedIterator
83- + ExactSizeIterator
84- + Iterator < Item = ( & ' a [ Attribute ] , Option < & ' a Pat < ' b > > , & ' a Expr < ' b > , Option < & ' a Expr < ' b > > ) > ,
85- {
86- if !span_contains_comment ( cx. sess ( ) . source_map ( ) , expr. span )
68+ let mut arms = arms
69+ . iter ( )
70+ . map ( |arm| ( cx. tcx . hir_attrs ( arm. hir_id ) , Some ( arm. pat ) , arm. body , arm. guard ) ) ;
71+ if !span_contains_comment ( cx. sess ( ) . source_map ( ) , e. span )
8772 && arms. len ( ) >= 2
88- && cx. typeck_results ( ) . expr_ty ( expr ) . is_bool ( )
73+ && cx. typeck_results ( ) . expr_ty ( e ) . is_bool ( )
8974 && let Some ( ( _, last_pat_opt, last_expr, _) ) = arms. next_back ( )
9075 && let arms_without_last = arms. clone ( )
9176 && let Some ( ( first_attrs, _, first_expr, first_guard) ) = arms. next ( )
@@ -133,16 +118,16 @@ where
133118 } ;
134119
135120 // strip potential borrows (#6503), but only if the type is a reference
136- let mut ex_new = ex ;
137- if let ExprKind :: AddrOf ( BorrowKind :: Ref , .., ex_inner) = ex . kind
121+ let mut ex_new = scrutinee ;
122+ if let ExprKind :: AddrOf ( BorrowKind :: Ref , .., ex_inner) = scrutinee . kind
138123 && let ty:: Ref ( ..) = cx. typeck_results ( ) . expr_ty ( ex_inner) . kind ( )
139124 {
140125 ex_new = ex_inner;
141126 }
142127 span_lint_and_sugg (
143128 cx,
144129 MATCH_LIKE_MATCHES_MACRO ,
145- expr . span ,
130+ e . span ,
146131 "match expression looks like `matches!` macro" ,
147132 "try" ,
148133 format ! (
0 commit comments