@@ -997,16 +997,23 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
997
997
if let Categorization :: Local ( local_id) = err. cmt . cat {
998
998
let span = self . tcx . map . span ( local_id) ;
999
999
if let Ok ( snippet) = self . tcx . sess . codemap ( ) . span_to_snippet ( span) {
1000
- if snippet. starts_with ( "ref " ) {
1001
- db. span_label ( span,
1002
- & format ! ( "use `{}` here to make mutable" ,
1003
- snippet. replace( "ref " , "ref mut " ) ) ) ;
1004
- } else if snippet != "self" {
1005
- db. span_label ( span,
1006
- & format ! ( "use `mut {}` here to make mutable" , snippet) ) ;
1000
+ if snippet. starts_with ( "ref mut " ) || snippet. starts_with ( "&mut " ) {
1001
+ db. span_label ( error_span, & format ! ( "cannot reborrow mutably" ) ) ;
1002
+ db. span_label ( error_span, & format ! ( "try removing `&mut` here" ) ) ;
1003
+ } else {
1004
+ if snippet. starts_with ( "ref " ) {
1005
+ db. span_label ( span,
1006
+ & format ! ( "use `{}` here to make mutable" ,
1007
+ snippet. replace( "ref " , "ref mut " ) ) ) ;
1008
+ } else if snippet != "self" {
1009
+ db. span_label ( span,
1010
+ & format ! ( "use `mut {}` here to make mutable" , snippet) ) ;
1011
+ }
1012
+ db. span_label ( error_span, & format ! ( "cannot borrow mutably" ) ) ;
1007
1013
}
1014
+ } else {
1015
+ db. span_label ( error_span, & format ! ( "cannot borrow mutably" ) ) ;
1008
1016
}
1009
- db. span_label ( error_span, & format ! ( "cannot borrow mutably" ) ) ;
1010
1017
}
1011
1018
}
1012
1019
}
0 commit comments