@@ -65,28 +65,28 @@ pub(super) fn check_match<'tcx>(
6565 scrutinee : & ' tcx Expr < ' _ > ,
6666 arms : & ' tcx [ Arm < ' tcx > ] ,
6767) -> bool {
68- let mut arms = arms
69- . iter ( )
70- . map ( |arm| ( cx. tcx . hir_attrs ( arm. hir_id ) , arm. pat , arm. body , arm. guard ) ) ;
71- if !span_contains_comment ( cx. sess ( ) . source_map ( ) , e. span )
72- && arms. len ( ) >= 2
68+ if let Some ( ( last_arm, arms_without_last) ) = arms. split_last ( )
69+ && let Some ( ( first_arm, middle_arms) ) = arms_without_last. split_first ( )
70+ && !span_contains_comment ( cx. sess ( ) . source_map ( ) , e. span )
7371 && cx. typeck_results ( ) . expr_ty ( e) . is_bool ( )
74- && let Some ( ( _ , last_pat, last_expr, _ ) ) = arms . next_back ( )
75- && let arms_without_last = arms . clone ( )
76- && let Some ( ( first_attrs , _ , first_expr , first_guard ) ) = arms . next ( )
72+ && let ( last_pat, last_expr) = ( last_arm . pat , last_arm . body )
73+ && let ( first_attrs , first_expr , first_guard ) =
74+ ( cx . tcx . hir_attrs ( first_arm . hir_id ) , first_arm . body , first_arm . guard )
7775 && let Some ( b0) = find_bool_lit ( first_expr)
7876 && let Some ( b1) = find_bool_lit ( last_expr)
7977 && b0 != b1
80- && ( first_guard. is_none ( ) || arms . len ( ) == 0 )
78+ && ( first_guard. is_none ( ) || middle_arms . is_empty ( ) )
8179 && first_attrs. is_empty ( )
82- && arms. all ( |( attrs, _, expr, guard) | attrs. is_empty ( ) && guard. is_none ( ) && find_bool_lit ( expr) == Some ( b0) )
80+ && middle_arms. iter ( ) . all ( |arm| {
81+ cx. tcx . hir_attrs ( arm. hir_id ) . is_empty ( ) && arm. guard . is_none ( ) && find_bool_lit ( arm. body ) == Some ( b0)
82+ } )
8383 {
8484 if !is_wild ( last_pat) {
8585 return false ;
8686 }
8787
88- for arm in arms_without_last. clone ( ) {
89- let pat = arm. 1 ;
88+ for arm in arms_without_last {
89+ let pat = arm. pat ;
9090 if !is_lint_allowed ( cx, REDUNDANT_PATTERN_MATCHING , pat. hir_id ) && is_some_wild ( pat. kind ) {
9191 return false ;
9292 }
@@ -98,10 +98,8 @@ pub(super) fn check_match<'tcx>(
9898 let pat = {
9999 use itertools:: Itertools as _;
100100 arms_without_last
101- . map ( |arm| {
102- let pat_span = arm. 1 . span ;
103- snippet_with_applicability ( cx, pat_span, ".." , & mut applicability)
104- } )
101+ . iter ( )
102+ . map ( |arm| snippet_with_applicability ( cx, arm. pat . span , ".." , & mut applicability) )
105103 . join ( " | " )
106104 } ;
107105 let pat_and_guard = if let Some ( g) = first_guard {
0 commit comments