@@ -580,7 +580,19 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
580580 if flow_state. inits . curr_state . contains ( & mpi) {
581581 // may already be assigned before reaching this statement;
582582 // report error.
583- self . report_illegal_reassignment ( context, ( lvalue, span) ) ;
583+ // FIXME: Not ideal, it only finds the assignment that lexically comes first
584+ let assigned_lvalue = & move_data. move_paths [ mpi] . lvalue ;
585+ let assignment_stmt = self . mir . basic_blocks ( ) . iter ( ) . filter_map ( |bb| {
586+ bb. statements . iter ( ) . find ( |stmt| {
587+ if let StatementKind :: Assign ( ref lv, _) = stmt. kind {
588+ * lv == * assigned_lvalue
589+ } else {
590+ false
591+ }
592+ } )
593+ } ) . next ( ) . unwrap ( ) ;
594+ self . report_illegal_reassignment (
595+ context, ( lvalue, span) , assignment_stmt. source_info . span ) ;
584596 }
585597 }
586598 }
@@ -982,11 +994,17 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
982994 err. emit ( ) ;
983995 }
984996
985- fn report_illegal_reassignment ( & mut self , _context : Context , ( lvalue, span) : ( & Lvalue , Span ) ) {
986- let mut err = self . tcx . cannot_reassign_immutable (
987- span, & self . describe_lvalue ( lvalue) , Origin :: Mir ) ;
988- // FIXME: add span labels for borrow and assignment points
989- err. emit ( ) ;
997+ fn report_illegal_reassignment ( & mut self ,
998+ _context : Context ,
999+ ( lvalue, span) : ( & Lvalue , Span ) ,
1000+ assigned_span : Span ) {
1001+ self . tcx . cannot_reassign_immutable ( span,
1002+ & self . describe_lvalue ( lvalue) ,
1003+ Origin :: Mir )
1004+ . span_label ( span, "re-assignment of immutable variable" )
1005+ . span_label ( assigned_span, format ! ( "first assignment to `{}`" ,
1006+ self . describe_lvalue( lvalue) ) )
1007+ . emit ( ) ;
9901008 }
9911009
9921010 fn report_assignment_to_static ( & mut self , _context : Context , ( lvalue, span) : ( & Lvalue , Span ) ) {
0 commit comments