@@ -14,7 +14,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
14
14
use rustc:: hir:: def:: * ;
15
15
use rustc:: hir:: def_id:: DefId ;
16
16
use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
17
- use rustc:: hir:: ptr:: P ;
18
17
use rustc:: hir:: { self , Pat , PatKind } ;
19
18
20
19
use smallvec:: smallvec;
@@ -76,15 +75,15 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
76
75
} ) ;
77
76
78
77
// Check legality of move bindings and `@` patterns.
79
- self . check_patterns ( false , slice :: from_ref ( & loc. pat ) ) ;
78
+ self . check_patterns ( false , & loc. pat ) ;
80
79
}
81
80
82
81
fn visit_body ( & mut self , body : & ' tcx hir:: Body ) {
83
82
intravisit:: walk_body ( self , body) ;
84
83
85
84
for param in & body. params {
86
85
self . check_irrefutable ( & param. pat , "function argument" ) ;
87
- self . check_patterns ( false , slice :: from_ref ( & param. pat ) ) ;
86
+ self . check_patterns ( false , & param. pat ) ;
88
87
}
89
88
}
90
89
}
@@ -122,11 +121,9 @@ impl PatternContext<'_, '_> {
122
121
}
123
122
124
123
impl < ' tcx > MatchVisitor < ' _ , ' tcx > {
125
- fn check_patterns ( & mut self , has_guard : bool , pats : & [ P < Pat > ] ) {
126
- check_legality_of_move_bindings ( self , has_guard, pats) ;
127
- for pat in pats {
128
- check_legality_of_bindings_in_at_patterns ( self , pat) ;
129
- }
124
+ fn check_patterns ( & mut self , has_guard : bool , pat : & Pat ) {
125
+ check_legality_of_move_bindings ( self , has_guard, pat) ;
126
+ check_legality_of_bindings_in_at_patterns ( self , pat) ;
130
127
}
131
128
132
129
fn check_match (
@@ -137,7 +134,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
137
134
) {
138
135
for arm in arms {
139
136
// First, check legality of move bindings.
140
- self . check_patterns ( arm. guard . is_some ( ) , & arm. top_pats_hack ( ) ) ;
137
+ self . check_patterns ( arm. guard . is_some ( ) , & arm. pat ) ;
141
138
142
139
// Second, if there is a guard on each arm, make sure it isn't
143
140
// assigning or borrowing anything mutably.
@@ -543,24 +540,18 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[Pattern<'_>]) -> Vec<Span> {
543
540
covered
544
541
}
545
542
546
- // Legality of move bindings checking
547
- fn check_legality_of_move_bindings (
548
- cx : & mut MatchVisitor < ' _ , ' _ > ,
549
- has_guard : bool ,
550
- pats : & [ P < Pat > ] ,
551
- ) {
543
+ // Check the legality of legality of by-move bindings.
544
+ fn check_legality_of_move_bindings ( cx : & mut MatchVisitor < ' _ , ' _ > , has_guard : bool , pat : & Pat ) {
552
545
let mut by_ref_span = None ;
553
- for pat in pats {
554
- pat. each_binding ( |_, hir_id, span, _path| {
555
- if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( hir_id) {
556
- if let ty:: BindByReference ( ..) = bm {
557
- by_ref_span = Some ( span) ;
558
- }
559
- } else {
560
- cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
546
+ pat. each_binding ( |_, hir_id, span, _| {
547
+ if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( hir_id) {
548
+ if let ty:: BindByReference ( ..) = bm {
549
+ by_ref_span = Some ( span) ;
561
550
}
562
- } )
563
- }
551
+ } else {
552
+ cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
553
+ }
554
+ } ) ;
564
555
565
556
let span_vec = & mut Vec :: new ( ) ;
566
557
let mut check_move = |p : & Pat , sub : Option < & Pat > | {
@@ -576,23 +567,22 @@ fn check_legality_of_move_bindings(
576
567
}
577
568
} ;
578
569
579
- for pat in pats {
580
- pat. walk ( |p| {
581
- if let PatKind :: Binding ( .., sub) = & p. node {
582
- if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
583
- if let ty:: BindByValue ( ..) = bm {
584
- let pat_ty = cx. tables . node_type ( p. hir_id ) ;
585
- if !pat_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env , pat. span ) {
586
- check_move ( p, sub. as_deref ( ) ) ;
587
- }
570
+ pat. walk ( |p| {
571
+ if let PatKind :: Binding ( .., sub) = & p. node {
572
+ if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
573
+ if let ty:: BindByValue ( ..) = bm {
574
+ let pat_ty = cx. tables . node_type ( p. hir_id ) ;
575
+ if !pat_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env , pat. span ) {
576
+ check_move ( p, sub. as_deref ( ) ) ;
588
577
}
589
- } else {
590
- cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
591
578
}
579
+ } else {
580
+ cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
592
581
}
593
- true
594
- } ) ;
595
- }
582
+ }
583
+ true
584
+ } ) ;
585
+
596
586
if !span_vec. is_empty ( ) {
597
587
let mut err = struct_span_err ! (
598
588
cx. tcx. sess,
@@ -603,7 +593,7 @@ fn check_legality_of_move_bindings(
603
593
if let Some ( by_ref_span) = by_ref_span {
604
594
err. span_label ( by_ref_span, "both by-ref and by-move used" ) ;
605
595
}
606
- for span in span_vec. iter ( ) {
596
+ for span in span_vec. iter ( ) {
607
597
err. span_label ( * span, "by-move pattern here" ) ;
608
598
}
609
599
err. emit ( ) ;
0 commit comments