@@ -563,40 +563,30 @@ fn check_legality_of_move_bindings(
563
563
}
564
564
} )
565
565
}
566
+
566
567
let span_vec = & mut Vec :: new ( ) ;
567
- let check_move = |
568
- cx : & mut MatchVisitor < ' _ , ' _ > ,
569
- p : & Pat ,
570
- sub : Option < & Pat > ,
571
- span_vec : & mut Vec < Span > ,
572
- | {
573
- // check legality of moving out of the enum
574
-
575
- // x @ Foo(..) is legal, but x @ Foo(y) isn't.
568
+ let mut check_move = |p : & Pat , sub : Option < & Pat > | {
569
+ // Check legality of moving out of the enum.
570
+ //
571
+ // `x @ Foo(..)` is legal, but `x @ Foo(y)` isn't.
576
572
if sub. map_or ( false , |p| p. contains_bindings ( ) ) {
577
- struct_span_err!( cx. tcx. sess, p. span, E0007 ,
578
- "cannot bind by-move with sub-bindings" )
573
+ struct_span_err ! ( cx. tcx. sess, p. span, E0007 , "cannot bind by-move with sub-bindings" )
579
574
. span_label ( p. span , "binds an already bound by-move value by moving it" )
580
575
. emit ( ) ;
581
- } else if !has_guard {
582
- if let Some ( _by_ref_span) = by_ref_span {
583
- span_vec. push( p. span) ;
584
- }
576
+ } else if !has_guard && by_ref_span. is_some ( ) {
577
+ span_vec. push ( p. span ) ;
585
578
}
586
579
} ;
587
580
588
581
for pat in pats {
589
582
pat. walk ( |p| {
590
- if let PatKind :: Binding ( _ , _ , _ , ref sub) = p. node {
583
+ if let PatKind :: Binding ( .. , sub) = & p. node {
591
584
if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
592
- match bm {
593
- ty:: BindByValue ( ..) => {
594
- let pat_ty = cx. tables. node_type( p. hir_id) ;
595
- if !pat_ty. is_copy_modulo_regions( cx. tcx, cx. param_env, pat. span) {
596
- check_move( cx, p, sub. as_ref( ) . map( |p| & * * p) , span_vec) ;
597
- }
585
+ if let ty:: BindByValue ( ..) = bm {
586
+ let pat_ty = cx. tables . node_type ( p. hir_id ) ;
587
+ if !pat_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env , pat. span ) {
588
+ check_move ( p, sub. as_deref ( ) ) ;
598
589
}
599
- _ => { }
600
590
}
601
591
} else {
602
592
cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
@@ -605,11 +595,10 @@ fn check_legality_of_move_bindings(
605
595
true
606
596
} ) ;
607
597
}
608
- if !span_vec. is_empty( ) {
609
- let span = MultiSpan :: from_spans( span_vec. clone( ) ) ;
598
+ if !span_vec. is_empty ( ) {
610
599
let mut err = struct_span_err ! (
611
600
cx. tcx. sess,
612
- span ,
601
+ MultiSpan :: from_spans ( span_vec . clone ( ) ) ,
613
602
E0009 ,
614
603
"cannot bind by-move and by-ref in the same pattern" ,
615
604
) ;
@@ -627,7 +616,7 @@ fn check_legality_of_move_bindings(
627
616
/// because of the way rvalues are handled in the borrow check. (See issue
628
617
/// #14587.)
629
618
fn check_legality_of_bindings_in_at_patterns ( cx : & MatchVisitor < ' _ , ' _ > , pat : & Pat ) {
630
- AtBindingPatternVisitor { cx: cx , bindings_allowed: true } . visit_pat( pat) ;
619
+ AtBindingPatternVisitor { cx, bindings_allowed : true } . visit_pat ( pat) ;
631
620
}
632
621
633
622
struct AtBindingPatternVisitor < ' a , ' b , ' tcx > {
0 commit comments