@@ -1422,13 +1422,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1422
1422
}
1423
1423
}
1424
1424
1425
- fn get_main_error_message ( & self , place : & Place < ' tcx > ) -> String {
1426
- match self . describe_place ( place) {
1427
- Some ( name) => format ! ( "immutable item `{}`" , name) ,
1428
- None => "immutable item" . to_owned ( ) ,
1429
- }
1430
- }
1431
-
1432
1425
/// Currently MoveData does not store entries for all places in
1433
1426
/// the input MIR. For example it will currently filter out
1434
1427
/// places that are Copy; thus we do not track places of shared
@@ -1533,6 +1526,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1533
1526
}
1534
1527
}
1535
1528
1529
+ fn specialized_description ( & self , place : & Place < ' tcx > ) -> Option < String > {
1530
+ if let Some ( name) = self . describe_place ( place) {
1531
+ Some ( format ! ( "`&`-reference `{}`" , name) )
1532
+ } else {
1533
+ None
1534
+ }
1535
+ }
1536
+
1537
+ fn get_main_error_message ( & self , place : & Place < ' tcx > ) -> String {
1538
+ match self . describe_place ( place) {
1539
+ Some ( name) => format ! ( "immutable item `{}`" , name) ,
1540
+ None => "immutable item" . to_owned ( ) ,
1541
+ }
1542
+ }
1543
+
1536
1544
/// Check the permissions for the given place and read or write kind
1537
1545
///
1538
1546
/// Returns true if an error is reported, false otherwise.
@@ -1566,7 +1574,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1566
1574
1567
1575
if place != place_err {
1568
1576
if let Some ( name) = self . describe_place ( place_err) {
1569
- err. note ( & format ! ( "value not mutable causing this error : `{}`" , name) ) ;
1577
+ err. note ( & format ! ( "the value which is causing this path not to be mutable is... : `{}`" , name) ) ;
1570
1578
}
1571
1579
}
1572
1580
@@ -1576,7 +1584,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1576
1584
if let Err ( place_err) = self . is_mutable ( place, is_local_mutation_allowed) {
1577
1585
error_reported = true ;
1578
1586
1579
- let err_info = match * place_err {
1587
+ let mut err_info = None ;
1588
+ match * place_err {
1580
1589
Place :: Projection ( ref proj) => {
1581
1590
match proj. elem {
1582
1591
ProjectionElem :: Deref => {
@@ -1585,32 +1594,27 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1585
1594
let locations = self . mir . find_assignments ( local) ;
1586
1595
if locations. len ( ) > 0 {
1587
1596
let item_msg = if error_reported {
1588
- if let Some ( name) =
1589
- self . describe_place ( place_err) {
1590
- let var = str:: replace ( & name, "*" , "" ) ;
1591
- format ! ( "`&`-reference `{}`" , var)
1592
- } else {
1593
- self . get_main_error_message ( place)
1597
+ match self . specialized_description ( & proj. base ) {
1598
+ Some ( msg) => msg,
1599
+ None => self . get_main_error_message ( place)
1594
1600
}
1595
1601
} else {
1596
1602
self . get_main_error_message ( place)
1597
1603
} ;
1598
- Some ( ( self . mir . source_info ( locations[ 0 ] ) . span ,
1604
+ err_info = Some ( ( self . mir . source_info ( locations[ 0 ] ) . span ,
1599
1605
"consider changing this to be a \
1600
1606
mutable reference: `&mut`", item_msg,
1601
- "cannot assign through `&`-reference" ) )
1602
- } else {
1603
- None
1607
+ "cannot assign through `&`-reference" ) ) ;
1604
1608
}
1605
1609
}
1606
- _ => None ,
1610
+ _ => { } ,
1607
1611
}
1608
1612
}
1609
- _ => None ,
1613
+ _ => { }
1610
1614
}
1611
1615
}
1612
- _ => None ,
1613
- } ;
1616
+ _ => { }
1617
+ }
1614
1618
1615
1619
if let Some ( ( err_help_span, err_help_stmt, item_msg, sec_span) ) = err_info {
1616
1620
let mut err = self . tcx . cannot_assign ( span, & item_msg, Origin :: Mir , true ) ;
@@ -1625,7 +1629,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1625
1629
err. span_label ( span, "cannot mutate" ) ;
1626
1630
if place != place_err {
1627
1631
if let Some ( name) = self . describe_place ( place_err) {
1628
- err. note ( & format ! ( "value not mutable causing this error : `{}`" ,
1632
+ err. note ( & format ! ( "the value which is causing this path not to be mutable is... : `{}`" ,
1629
1633
name) ) ;
1630
1634
}
1631
1635
}
0 commit comments