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