@@ -14,7 +14,6 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1414use rustc_errors:: Applicability ;
1515use std:: cmp:: Ordering ;
1616use std:: collections:: Bound ;
17- use std:: ops:: Deref ;
1817use syntax:: ast:: LitKind ;
1918use syntax:: source_map:: Span ;
2019
@@ -255,9 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
255254
256255#[ rustfmt:: skip]
257256fn check_single_match ( cx : & LateContext < ' _ , ' _ > , ex : & Expr , arms : & [ Arm ] , expr : & Expr ) {
258- if arms. len ( ) == 2 &&
259- arms[ 0 ] . pats . len ( ) == 1 && arms[ 0 ] . guard . is_none ( ) &&
260- arms[ 1 ] . pats . len ( ) == 1 && arms[ 1 ] . guard . is_none ( ) {
257+ if arms. len ( ) == 2 && arms[ 0 ] . guard . is_none ( ) && arms[ 1 ] . guard . is_none ( ) {
261258 let els = remove_blocks ( & arms[ 1 ] . body ) ;
262259 let els = if is_unit_expr ( els) {
263260 None
@@ -283,7 +280,7 @@ fn check_single_match_single_pattern(
283280 expr : & Expr ,
284281 els : Option < & Expr > ,
285282) {
286- if is_wild ( & arms[ 1 ] . pats [ 0 ] ) {
283+ if is_wild ( & arms[ 1 ] . pat ) {
287284 report_single_match_single_pattern ( cx, ex, arms, expr, els) ;
288285 }
289286}
@@ -308,7 +305,7 @@ fn report_single_match_single_pattern(
308305 "try this" ,
309306 format ! (
310307 "if let {} = {} {}{}" ,
311- snippet( cx, arms[ 0 ] . pats [ 0 ] . span, ".." ) ,
308+ snippet( cx, arms[ 0 ] . pat . span, ".." ) ,
312309 snippet( cx, ex. span, ".." ) ,
313310 expr_block( cx, & arms[ 0 ] . body, None , ".." ) ,
314311 els_str,
@@ -336,7 +333,7 @@ fn check_single_match_opt_like(
336333 ( & paths:: RESULT , "Ok" ) ,
337334 ] ;
338335
339- let path = match arms[ 1 ] . pats [ 0 ] . node {
336+ let path = match arms[ 1 ] . pat . node {
340337 PatKind :: TupleStruct ( ref path, ref inner, _) => {
341338 // Contains any non wildcard patterns (e.g., `Err(err)`)?
342339 if !inner. iter ( ) . all ( is_wild) {
@@ -365,9 +362,9 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex
365362 expr. span ,
366363 "you seem to be trying to match on a boolean expression" ,
367364 move |db| {
368- if arms. len ( ) == 2 && arms [ 0 ] . pats . len ( ) == 1 {
365+ if arms. len ( ) == 2 {
369366 // no guards
370- let exprs = if let PatKind :: Lit ( ref arm_bool) = arms[ 0 ] . pats [ 0 ] . node {
367+ let exprs = if let PatKind :: Lit ( ref arm_bool) = arms[ 0 ] . pat . node {
371368 if let ExprKind :: Lit ( ref lit) = arm_bool. node {
372369 match lit. node {
373370 LitKind :: Bool ( true ) => Some ( ( & * arms[ 0 ] . body , & * arms[ 1 ] . body ) ) ,
@@ -446,7 +443,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
446443 let ex_ty = walk_ptrs_ty ( cx. tables . expr_ty ( ex) ) ;
447444 if match_type ( cx, ex_ty, & paths:: RESULT ) {
448445 for arm in arms {
449- if let PatKind :: TupleStruct ( ref path, ref inner, _) = arm. pats [ 0 ] . node {
446+ if let PatKind :: TupleStruct ( ref path, ref inner, _) = arm. pat . node {
450447 let path_str = print:: to_string ( print:: NO_ANN , |s| s. print_qpath ( path, false ) ) ;
451448 if_chain ! {
452449 if path_str == "Err" ;
@@ -457,9 +454,9 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
457454 // `Err(_)` arm with `panic!` found
458455 span_note_and_lint( cx,
459456 MATCH_WILD_ERR_ARM ,
460- arm. pats [ 0 ] . span,
457+ arm. pat . span,
461458 "Err(_) will match all errors, maybe not a good idea" ,
462- arm. pats [ 0 ] . span,
459+ arm. pat . span,
463460 "to remove this warning, match each error separately \
464461 or use unreachable macro") ;
465462 }
@@ -482,13 +479,11 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
482479 let mut wildcard_span = None ;
483480 let mut wildcard_ident = None ;
484481 for arm in arms {
485- for pat in & arm. pats {
486- if let PatKind :: Wild = pat. node {
487- wildcard_span = Some ( pat. span ) ;
488- } else if let PatKind :: Binding ( _, _, ident, None ) = pat. node {
489- wildcard_span = Some ( pat. span ) ;
490- wildcard_ident = Some ( ident) ;
491- }
482+ if let PatKind :: Wild = arm. pat . node {
483+ wildcard_span = Some ( arm. pat . span ) ;
484+ } else if let PatKind :: Binding ( _, _, ident, None ) = arm. pat . node {
485+ wildcard_span = Some ( arm. pat . span ) ;
486+ wildcard_ident = Some ( ident) ;
492487 }
493488 }
494489
@@ -510,15 +505,13 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
510505 // covered by the set of guards that cover it, but that's really hard to do.
511506 continue ;
512507 }
513- for pat in & arm. pats {
514- if let PatKind :: Path ( ref path) = pat. deref ( ) . node {
515- if let QPath :: Resolved ( _, p) = path {
516- missing_variants. retain ( |e| e. ctor_def_id != Some ( p. res . def_id ( ) ) ) ;
517- }
518- } else if let PatKind :: TupleStruct ( ref path, ..) = pat. deref ( ) . node {
519- if let QPath :: Resolved ( _, p) = path {
520- missing_variants. retain ( |e| e. ctor_def_id != Some ( p. res . def_id ( ) ) ) ;
521- }
508+ if let PatKind :: Path ( ref path) = arm. pat . node {
509+ if let QPath :: Resolved ( _, p) = path {
510+ missing_variants. retain ( |e| e. ctor_def_id != Some ( p. res . def_id ( ) ) ) ;
511+ }
512+ } else if let PatKind :: TupleStruct ( ref path, ..) = arm. pat . node {
513+ if let QPath :: Resolved ( _, p) = path {
514+ missing_variants. retain ( |e| e. ctor_def_id != Some ( p. res . def_id ( ) ) ) ;
522515 }
523516 }
524517 }
@@ -588,9 +581,9 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr:
588581 )
589582 } ;
590583
591- suggs. extend ( arms. iter ( ) . flat_map ( |a| & a . pats ) . filter_map ( |p | {
592- if let PatKind :: Ref ( ref refp, _) = p . node {
593- Some ( ( p . span , snippet ( cx, refp. span , ".." ) . to_string ( ) ) )
584+ suggs. extend ( arms. iter ( ) . filter_map ( |a | {
585+ if let PatKind :: Ref ( ref refp, _) = a . pat . node {
586+ Some ( ( a . pat . span , snippet ( cx, refp. span , ".." ) . to_string ( ) ) )
594587 } else {
595588 None
596589 }
@@ -605,12 +598,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr:
605598}
606599
607600fn check_match_as_ref ( cx : & LateContext < ' _ , ' _ > , ex : & Expr , arms : & [ Arm ] , expr : & Expr ) {
608- if arms. len ( ) == 2
609- && arms[ 0 ] . pats . len ( ) == 1
610- && arms[ 0 ] . guard . is_none ( )
611- && arms[ 1 ] . pats . len ( ) == 1
612- && arms[ 1 ] . guard . is_none ( )
613- {
601+ if arms. len ( ) == 2 && arms[ 0 ] . guard . is_none ( ) && arms[ 1 ] . guard . is_none ( ) {
614602 let arm_ref: Option < BindingAnnotation > = if is_none_arm ( & arms[ 0 ] ) {
615603 is_ref_some_arm ( & arms[ 1 ] )
616604 } else if is_none_arm ( & arms[ 1 ] ) {
@@ -666,14 +654,9 @@ fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec<Sp
666654 arms. iter ( )
667655 . flat_map ( |arm| {
668656 if let Arm {
669- ref pats , guard : None , ..
657+ ref pat , guard : None , ..
670658 } = * arm
671659 {
672- pats. iter ( )
673- } else {
674- [ ] . iter ( )
675- }
676- . filter_map ( |pat| {
677660 if let PatKind :: Range ( ref lhs, ref rhs, ref range_end) = pat. node {
678661 let lhs = constant ( cx, cx. tables , lhs) ?. 0 ;
679662 let rhs = constant ( cx, cx. tables , rhs) ?. 0 ;
@@ -694,9 +677,8 @@ fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec<Sp
694677 node : ( value. clone ( ) , Bound :: Included ( value) ) ,
695678 } ) ;
696679 }
697-
698- None
699- } )
680+ }
681+ None
700682 } )
701683 . collect ( )
702684}
@@ -743,7 +725,7 @@ fn is_unit_expr(expr: &Expr) -> bool {
743725
744726// Checks if arm has the form `None => None`
745727fn is_none_arm ( arm : & Arm ) -> bool {
746- match arm. pats [ 0 ] . node {
728+ match arm. pat . node {
747729 PatKind :: Path ( ref path) if match_qpath ( path, & paths:: OPTION_NONE ) => true ,
748730 _ => false ,
749731 }
@@ -752,7 +734,7 @@ fn is_none_arm(arm: &Arm) -> bool {
752734// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
753735fn is_ref_some_arm ( arm : & Arm ) -> Option < BindingAnnotation > {
754736 if_chain ! {
755- if let PatKind :: TupleStruct ( ref path, ref pats, _) = arm. pats [ 0 ] . node;
737+ if let PatKind :: TupleStruct ( ref path, ref pats, _) = arm. pat . node;
756738 if pats. len( ) == 1 && match_qpath( path, & paths:: OPTION_SOME ) ;
757739 if let PatKind :: Binding ( rb, .., ident, _) = pats[ 0 ] . node;
758740 if rb == BindingAnnotation :: Ref || rb == BindingAnnotation :: RefMut ;
@@ -772,9 +754,8 @@ fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
772754fn has_only_ref_pats ( arms : & [ Arm ] ) -> bool {
773755 let mapped = arms
774756 . iter ( )
775- . flat_map ( |a| & a. pats )
776- . map ( |p| {
777- match p. node {
757+ . map ( |a| {
758+ match a. pat . node {
778759 PatKind :: Ref ( ..) => Some ( true ) , // &-patterns
779760 PatKind :: Wild => Some ( false ) , // an "anything" wildcard is also fine
780761 _ => None , // any other pattern is not fine
0 commit comments