@@ -35,7 +35,7 @@ use std::slice;
35
35
36
36
use syntax:: ast;
37
37
use syntax:: ptr:: P ;
38
- use syntax_pos:: { Span , DUMMY_SP } ;
38
+ use syntax_pos:: { Span , DUMMY_SP , MultiSpan } ;
39
39
40
40
struct OuterVisitor < ' a , ' tcx : ' a > { tcx : TyCtxt < ' a , ' tcx , ' tcx > }
41
41
@@ -527,8 +527,8 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
527
527
}
528
528
} )
529
529
}
530
-
531
- let check_move = |p : & Pat , sub : Option < & Pat > | {
530
+ let span_vec = & mut Vec :: new ( ) ;
531
+ let check_move = |p : & Pat , sub : Option < & Pat > , span_vec : & mut Vec < Span > | {
532
532
// check legality of moving out of the enum
533
533
534
534
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
@@ -546,16 +546,8 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
546
546
crate attributes to enable") ;
547
547
}
548
548
err. emit ( ) ;
549
- } else if let Some ( by_ref_span) = by_ref_span {
550
- struct_span_err ! (
551
- cx. tcx. sess,
552
- p. span,
553
- E0009 ,
554
- "cannot bind by-move and by-ref in the same pattern" ,
555
- )
556
- . span_label ( p. span , "by-move pattern here" )
557
- . span_label ( by_ref_span, "both by-ref and by-move used" )
558
- . emit ( ) ;
549
+ } else if let Some ( _by_ref_span) = by_ref_span {
550
+ span_vec. push ( p. span ) ;
559
551
}
560
552
} ;
561
553
@@ -567,7 +559,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
567
559
ty:: BindByValue ( ..) => {
568
560
let pat_ty = cx. tables . node_id_to_type ( p. hir_id ) ;
569
561
if pat_ty. moves_by_default ( cx. tcx , cx. param_env , pat. span ) {
570
- check_move ( p, sub. as_ref ( ) . map ( |p| & * * p) ) ;
562
+ check_move ( p, sub. as_ref ( ) . map ( |p| & * * p) , span_vec ) ;
571
563
}
572
564
}
573
565
_ => { }
@@ -579,6 +571,20 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
579
571
true
580
572
} ) ;
581
573
}
574
+ if !span_vec. is_empty ( ) {
575
+ let span = MultiSpan :: from_spans ( span_vec. clone ( ) ) ;
576
+ let mut err = struct_span_err ! (
577
+ cx. tcx. sess,
578
+ span,
579
+ E0009 ,
580
+ "cannot bind by-move and by-ref in the same pattern" ,
581
+ ) ;
582
+ err. span_label ( by_ref_span. unwrap ( ) , "both by-ref and by-move used" ) ;
583
+ for span in span_vec. iter ( ) {
584
+ err. span_label ( * span, "by-move pattern here" ) ;
585
+ }
586
+ err. emit ( ) ;
587
+ }
582
588
}
583
589
584
590
/// Ensures that a pattern guard doesn't borrow by mutable reference or
0 commit comments