@@ -658,8 +658,8 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
658
658
name,
659
659
tables. node_type( pat. hir_id) ,
660
660
) ;
661
- sess. struct_span_err ( pat. span , & format ! ( "borrow of moved value: `{}`" , name ) )
662
- . span_label ( binding_span, "value moved here" )
661
+ sess. struct_span_err ( pat. span , "borrow of moved value" )
662
+ . span_label ( binding_span, format ! ( "value moved into `{}` here" , name ) )
663
663
. span_label ( binding_span, occurs_because)
664
664
. span_labels ( conflicts_ref, "value borrowed here after move" )
665
665
. emit ( ) ;
@@ -675,50 +675,62 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
675
675
let mut conflicts_move = Vec :: new ( ) ;
676
676
let mut conflicts_mut_mut = Vec :: new ( ) ;
677
677
let mut conflicts_mut_ref = Vec :: new ( ) ;
678
- sub. each_binding ( |_, hir_id, span, _| match tables. extract_binding_mode ( sess, hir_id, span) {
679
- Some ( ty:: BindByReference ( mut_inner) ) => match ( mut_outer, mut_inner) {
680
- ( Mutability :: Not , Mutability :: Not ) => { } // Both sides are `ref`.
681
- ( Mutability :: Mut , Mutability :: Mut ) => conflicts_mut_mut. push ( span) , // 2x `ref mut`.
682
- _ => conflicts_mut_ref. push ( span) , // `ref` + `ref mut` in either direction.
683
- } ,
684
- Some ( ty:: BindByValue ( _) ) if is_binding_by_move ( cx, hir_id, span) => {
685
- conflicts_move. push ( span) // `ref mut?` + by-move conflict.
678
+ sub. each_binding ( |_, hir_id, span, name| {
679
+ match tables. extract_binding_mode ( sess, hir_id, span) {
680
+ Some ( ty:: BindByReference ( mut_inner) ) => match ( mut_outer, mut_inner) {
681
+ ( Mutability :: Not , Mutability :: Not ) => { } // Both sides are `ref`.
682
+ ( Mutability :: Mut , Mutability :: Mut ) => conflicts_mut_mut. push ( ( span, name) ) , // 2x `ref mut`.
683
+ _ => conflicts_mut_ref. push ( ( span, name) ) , // `ref` + `ref mut` in either direction.
684
+ } ,
685
+ Some ( ty:: BindByValue ( _) ) if is_binding_by_move ( cx, hir_id, span) => {
686
+ conflicts_move. push ( ( span, name) ) // `ref mut?` + by-move conflict.
687
+ }
688
+ Some ( ty:: BindByValue ( _) ) | None => { } // `ref mut?` + by-copy is fine.
686
689
}
687
- Some ( ty:: BindByValue ( _) ) | None => { } // `ref mut?` + by-copy is fine.
688
690
} ) ;
689
691
690
692
// Report errors if any.
691
693
if !conflicts_mut_mut. is_empty ( ) {
692
694
// Report mutability conflicts for e.g. `ref mut x @ Some(ref mut y)`.
693
- let msg = & format ! ( "cannot borrow `{}` as mutable more than once at a time" , name) ;
694
- sess. struct_span_err ( pat. span , msg)
695
- . span_label ( binding_span, "first mutable borrow occurs here" )
696
- . span_labels ( conflicts_mut_mut, "another mutable borrow occurs here" )
697
- . span_labels ( conflicts_mut_ref, "also borrowed as immutable here" )
698
- . span_labels ( conflicts_move, "also moved here" )
699
- . emit ( ) ;
695
+ let mut err = sess
696
+ . struct_span_err ( pat. span , "cannot borrow value as mutable more than once at a time" ) ;
697
+ err. span_label ( binding_span, format ! ( "first mutable borrow, by `{}`, occurs here" , name) ) ;
698
+ for ( span, name) in conflicts_mut_mut {
699
+ err. span_label ( span, format ! ( "another mutable borrow, by `{}`, occurs here" , name) ) ;
700
+ }
701
+ for ( span, name) in conflicts_mut_ref {
702
+ err. span_label ( span, format ! ( "also borrowed as immutable, by `{}`, here" , name) ) ;
703
+ }
704
+ for ( span, name) in conflicts_move {
705
+ err. span_label ( span, format ! ( "also moved into `{}` here" , name) ) ;
706
+ }
707
+ err. emit ( ) ;
700
708
} else if !conflicts_mut_ref. is_empty ( ) {
701
709
// Report mutability conflicts for e.g. `ref x @ Some(ref mut y)` or the converse.
702
710
let ( primary, also) = match mut_outer {
703
711
Mutability :: Mut => ( "mutable" , "immutable" ) ,
704
712
Mutability :: Not => ( "immutable" , "mutable" ) ,
705
713
} ;
706
- let msg = & format ! (
707
- "cannot borrow `{}` as {} because it is also borrowed as {}" ,
708
- name, also, primary,
709
- ) ;
710
- sess. struct_span_err ( pat. span , msg)
711
- . span_label ( binding_span, format ! ( "{} borrow occurs here" , primary) )
712
- . span_labels ( conflicts_mut_ref, format ! ( "{} borrow occurs here" , also) )
713
- . span_labels ( conflicts_move, "also moved here" )
714
- . emit ( ) ;
714
+ let msg =
715
+ format ! ( "cannot borrow value as {} because it is also borrowed as {}" , also, primary) ;
716
+ let mut err = sess. struct_span_err ( pat. span , & msg) ;
717
+ err. span_label ( binding_span, format ! ( "{} borrow, by `{}`, occurs here" , primary, name) ) ;
718
+ for ( span, name) in conflicts_mut_ref {
719
+ err. span_label ( span, format ! ( "{} borrow, by `{}`, occurs here" , also, name) ) ;
720
+ }
721
+ for ( span, name) in conflicts_move {
722
+ err. span_label ( span, format ! ( "also moved into `{}` here" , name) ) ;
723
+ }
724
+ err. emit ( ) ;
715
725
} else if !conflicts_move. is_empty ( ) {
716
726
// Report by-ref and by-move conflicts, e.g. `ref x @ y`.
717
- let msg = & format ! ( "cannot move out of `{}` because it is borrowed" , name) ;
718
- sess. struct_span_err ( pat. span , msg)
719
- . span_label ( binding_span, format ! ( "borrow of `{}` occurs here" , name) )
720
- . span_labels ( conflicts_move, format ! ( "move out of `{}` occurs here" , name) )
721
- . emit ( ) ;
727
+ let mut err =
728
+ sess. struct_span_err ( pat. span , "cannot move out of value because it is borrowed" ) ;
729
+ err. span_label ( binding_span, format ! ( "value borrowed, by `{}`, here" , name) ) ;
730
+ for ( span, name) in conflicts_move {
731
+ err. span_label ( span, format ! ( "value moved into `{}` here" , name) ) ;
732
+ }
733
+ err. emit ( ) ;
722
734
}
723
735
}
724
736
0 commit comments