@@ -15,7 +15,7 @@ use rustc::hir::def_id::{DefId};
15
15
use rustc:: infer:: { InferCtxt } ;
16
16
use rustc:: ty:: { self , TyCtxt , ParamEnv } ;
17
17
use rustc:: ty:: maps:: Providers ;
18
- use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Location , Lvalue , Local } ;
18
+ use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Field , Location , Lvalue , Local } ;
19
19
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
20
20
use rustc:: mir:: { Statement , StatementKind , Terminator , TerminatorKind } ;
21
21
use transform:: nll;
@@ -1577,15 +1577,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1577
1577
// End-user visible description of `lvalue`
1578
1578
fn describe_lvalue ( & self , lvalue : & Lvalue < ' tcx > ) -> String {
1579
1579
let mut buf = String :: new ( ) ;
1580
- self . append_lvalue_to_string ( lvalue, & mut buf, None ) ;
1580
+ self . append_lvalue_to_string ( lvalue, & mut buf, false ) ;
1581
1581
buf
1582
1582
}
1583
1583
1584
1584
// Appends end-user visible description of `lvalue` to `buf`.
1585
1585
fn append_lvalue_to_string ( & self ,
1586
1586
lvalue : & Lvalue < ' tcx > ,
1587
1587
buf : & mut String ,
1588
- autoderef : Option < bool > ) {
1588
+ mut autoderef : bool ) {
1589
1589
match * lvalue {
1590
1590
Lvalue :: Local ( local) => {
1591
1591
self . append_local_to_string ( local, buf, "_" ) ;
@@ -1594,38 +1594,35 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1594
1594
buf. push_str ( & format ! ( "{}" , & self . tcx. item_name( static_. def_id) ) ) ;
1595
1595
}
1596
1596
Lvalue :: Projection ( ref proj) => {
1597
- let mut autoderef = autoderef. unwrap_or ( false ) ;
1598
-
1599
1597
match proj. elem {
1600
1598
ProjectionElem :: Deref => {
1601
1599
if autoderef {
1602
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1600
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1603
1601
} else {
1604
- buf. push_str ( & "(*" ) ;
1605
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1606
- buf. push_str ( & ")" ) ;
1602
+ buf. push_str ( & "*" ) ;
1603
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1607
1604
}
1608
1605
} ,
1609
1606
ProjectionElem :: Downcast ( ..) => {
1610
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1607
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1611
1608
} ,
1612
1609
ProjectionElem :: Field ( field, _ty) => {
1613
1610
autoderef = true ;
1614
1611
let is_projection_from_ty_closure = proj. base . ty ( self . mir , self . tcx )
1615
1612
. to_ty ( self . tcx ) . is_closure ( ) ;
1616
1613
1617
- let field_name = self . describe_field ( & proj. base , field. index ( ) ) ;
1614
+ let field_name = self . describe_field ( & proj. base , field) ;
1618
1615
if is_projection_from_ty_closure {
1619
1616
buf. push_str ( & format ! ( "{}" , field_name) ) ;
1620
1617
} else {
1621
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1618
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1622
1619
buf. push_str ( & format ! ( ".{}" , field_name) ) ;
1623
1620
}
1624
1621
} ,
1625
1622
ProjectionElem :: Index ( index) => {
1626
1623
autoderef = true ;
1627
1624
1628
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1625
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1629
1626
buf. push_str ( "[" ) ;
1630
1627
self . append_local_to_string ( index, buf, ".." ) ;
1631
1628
buf. push_str ( "]" ) ;
@@ -1635,7 +1632,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1635
1632
// Since it isn't possible to borrow an element on a particular index and
1636
1633
// then use another while the borrow is held, don't output indices details
1637
1634
// to avoid confusing the end-user
1638
- self . append_lvalue_to_string ( & proj. base , buf, Some ( autoderef) ) ;
1635
+ self . append_lvalue_to_string ( & proj. base , buf, autoderef) ;
1639
1636
buf. push_str ( & "[..]" ) ;
1640
1637
} ,
1641
1638
} ;
@@ -1653,66 +1650,65 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1653
1650
}
1654
1651
}
1655
1652
1656
- // FIXME Instead of passing usize, Field should be passed
1657
- // End-user visible description of the `field_index`nth field of `base`
1658
- fn describe_field ( & self , base : & Lvalue , field_index : usize ) -> String {
1653
+ // End-user visible description of the `field`nth field of `base`
1654
+ fn describe_field ( & self , base : & Lvalue , field : Field ) -> String {
1659
1655
match * base {
1660
1656
Lvalue :: Local ( local) => {
1661
1657
let local = & self . mir . local_decls [ local] ;
1662
- self . describe_field_from_ty ( & local. ty , field_index )
1658
+ self . describe_field_from_ty ( & local. ty , field )
1663
1659
} ,
1664
1660
Lvalue :: Static ( ref static_) => {
1665
- self . describe_field_from_ty ( & static_. ty , field_index )
1661
+ self . describe_field_from_ty ( & static_. ty , field )
1666
1662
} ,
1667
1663
Lvalue :: Projection ( ref proj) => {
1668
1664
match proj. elem {
1669
1665
ProjectionElem :: Deref =>
1670
- self . describe_field ( & proj. base , field_index ) ,
1666
+ self . describe_field ( & proj. base , field ) ,
1671
1667
ProjectionElem :: Downcast ( def, variant_index) =>
1672
- format ! ( "{}" , def. variants[ variant_index] . fields[ field_index ] . name) ,
1668
+ format ! ( "{}" , def. variants[ variant_index] . fields[ field . index ( ) ] . name) ,
1673
1669
ProjectionElem :: Field ( _, field_type) =>
1674
- self . describe_field_from_ty ( & field_type, field_index ) ,
1670
+ self . describe_field_from_ty ( & field_type, field ) ,
1675
1671
ProjectionElem :: Index ( ..)
1676
1672
| ProjectionElem :: ConstantIndex { .. }
1677
1673
| ProjectionElem :: Subslice { .. } =>
1678
- format ! ( "{}" , self . describe_field( & proj. base, field_index ) ) ,
1674
+ format ! ( "{}" , self . describe_field( & proj. base, field ) ) ,
1679
1675
}
1680
1676
}
1681
1677
}
1682
1678
}
1683
1679
1684
1680
// End-user visible description of the `field_index`nth field of `ty`
1685
- fn describe_field_from_ty ( & self , ty : & ty:: Ty , field_index : usize ) -> String {
1681
+ fn describe_field_from_ty ( & self , ty : & ty:: Ty , field : Field ) -> String {
1686
1682
if ty. is_box ( ) {
1687
1683
// If the type is a box, the field is described from the boxed type
1688
- self . describe_field_from_ty ( & ty. boxed_ty ( ) , field_index )
1684
+ self . describe_field_from_ty ( & ty. boxed_ty ( ) , field )
1689
1685
}
1690
1686
else {
1691
1687
match ty. sty {
1692
1688
ty:: TyAdt ( def, _) => {
1693
1689
if def. is_enum ( ) {
1694
- format ! ( "{}" , field_index )
1690
+ format ! ( "{}" , field . index ( ) )
1695
1691
}
1696
1692
else {
1697
- format ! ( "{}" , def. struct_variant( ) . fields[ field_index ] . name)
1693
+ format ! ( "{}" , def. struct_variant( ) . fields[ field . index ( ) ] . name)
1698
1694
}
1699
1695
} ,
1700
1696
ty:: TyTuple ( _, _) => {
1701
- format ! ( "{}" , field_index )
1697
+ format ! ( "{}" , field . index ( ) )
1702
1698
} ,
1703
1699
ty:: TyRef ( _, tnm) | ty:: TyRawPtr ( tnm) => {
1704
- self . describe_field_from_ty ( & tnm. ty , field_index )
1700
+ self . describe_field_from_ty ( & tnm. ty , field )
1705
1701
} ,
1706
1702
ty:: TyArray ( ty, _) | ty:: TySlice ( ty) => {
1707
- self . describe_field_from_ty ( & ty, field_index )
1703
+ self . describe_field_from_ty ( & ty, field )
1708
1704
} ,
1709
1705
ty:: TyClosure ( closure_def_id, _) => {
1710
1706
// Convert the def-id into a node-id. node-ids are only valid for
1711
1707
// the local code in the current crate, so this returns an `Option` in case
1712
1708
// the closure comes from another crate. But in that case we wouldn't
1713
1709
// be borrowck'ing it, so we can just unwrap:
1714
1710
let node_id = self . tcx . hir . as_local_node_id ( closure_def_id) . unwrap ( ) ;
1715
- let freevar = self . tcx . with_freevars ( node_id, |fv| fv[ field_index ] ) ;
1711
+ let freevar = self . tcx . with_freevars ( node_id, |fv| fv[ field . index ( ) ] ) ;
1716
1712
1717
1713
self . tcx . hir . name ( freevar. var_id ( ) ) . to_string ( )
1718
1714
}
0 commit comments