@@ -419,7 +419,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
419419 self . each_borrow_involving_path (
420420 context, lvalue_span. 0 , flow_state, |this, _idx, borrow| {
421421 if !borrow. compatible_with ( BorrowKind :: Shared ) {
422- this. report_use_while_mutably_borrowed ( context, lvalue_span) ;
422+ this. report_use_while_mutably_borrowed ( context, lvalue_span, borrow ) ;
423423 Control :: Break
424424 } else {
425425 Control :: Continue
@@ -914,11 +914,17 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
914914
915915 fn report_use_while_mutably_borrowed ( & mut self ,
916916 _context : Context ,
917- ( lvalue, span) : ( & Lvalue , Span ) ) {
917+ ( lvalue, span) : ( & Lvalue , Span ) ,
918+ borrow : & BorrowData ) {
919+ let described_lvalue = self . describe_lvalue ( lvalue) ;
920+ let borrow_span = self . retrieve_borrow_span ( borrow) ;
921+
918922 let mut err = self . tcx . cannot_use_when_mutably_borrowed (
919- span, & self . describe_lvalue ( lvalue) , Origin :: Mir ) ;
920- // FIXME 1: add span_label for "borrow of `()` occurs here"
921- // FIXME 2: add span_label for "use of `{}` occurs here"
923+ span, & described_lvalue, Origin :: Mir ) ;
924+
925+ err. span_label ( borrow_span, format ! ( "borrow of `{}` occurs here" , described_lvalue) ) ;
926+ err. span_label ( span, format ! ( "use of borrowed `{}`" , described_lvalue) ) ;
927+
922928 err. emit ( ) ;
923929 }
924930
@@ -998,7 +1004,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
9981004 ProjectionElem :: Downcast ( ..) =>
9991005 ( "" , format ! ( "" ) , None ) , // (dont emit downcast info)
10001006 ProjectionElem :: Field ( field, _ty) =>
1001- ( "" , format ! ( ".{}" , field. index( ) ) , None ) ,
1007+ ( "" , format ! ( ".{}" , field. index( ) ) , None ) , // FIXME: report name of field
10021008 ProjectionElem :: Index ( index) =>
10031009 ( "" , format ! ( "" ) , Some ( index) ) ,
10041010 ProjectionElem :: ConstantIndex { offset, min_length, from_end : true } =>
@@ -1024,6 +1030,13 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
10241030 }
10251031 }
10261032 }
1033+
1034+ // Retrieve span of given borrow from the current MIR representation
1035+ fn retrieve_borrow_span ( & self , borrow : & BorrowData ) -> Span {
1036+ self . mir . basic_blocks ( ) [ borrow. location . block ]
1037+ . statements [ borrow. location . statement_index ]
1038+ . source_info . span
1039+ }
10271040}
10281041
10291042impl < ' c , ' b , ' a : ' b +' c , ' gcx , ' tcx : ' a > MirBorrowckCtxt < ' c , ' b , ' a , ' gcx , ' tcx > {
0 commit comments