@@ -419,7 +419,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
419
419
self . each_borrow_involving_path (
420
420
context, lvalue_span. 0 , flow_state, |this, _idx, borrow| {
421
421
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 ) ;
423
423
Control :: Break
424
424
} else {
425
425
Control :: Continue
@@ -914,11 +914,17 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
914
914
915
915
fn report_use_while_mutably_borrowed ( & mut self ,
916
916
_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
+
918
922
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
+
922
928
err. emit ( ) ;
923
929
}
924
930
@@ -998,7 +1004,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
998
1004
ProjectionElem :: Downcast ( ..) =>
999
1005
( "" , format ! ( "" ) , None ) , // (dont emit downcast info)
1000
1006
ProjectionElem :: Field ( field, _ty) =>
1001
- ( "" , format ! ( ".{}" , field. index( ) ) , None ) ,
1007
+ ( "" , format ! ( ".{}" , field. index( ) ) , None ) , // FIXME: report name of field
1002
1008
ProjectionElem :: Index ( index) =>
1003
1009
( "" , format ! ( "" ) , Some ( index) ) ,
1004
1010
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>
1024
1030
}
1025
1031
}
1026
1032
}
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
+ }
1027
1040
}
1028
1041
1029
1042
impl < ' c , ' b , ' a : ' b +' c , ' gcx , ' tcx : ' a > MirBorrowckCtxt < ' c , ' b , ' a , ' gcx , ' tcx > {
0 commit comments