@@ -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;
@@ -1611,7 +1611,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1611
1611
let is_projection_from_ty_closure = proj. base . ty ( self . mir , self . tcx )
1612
1612
. to_ty ( self . tcx ) . is_closure ( ) ;
1613
1613
1614
- let field_name = self . describe_field ( & proj. base , field. index ( ) ) ;
1614
+ let field_name = self . describe_field ( & proj. base , field) ;
1615
1615
if is_projection_from_ty_closure {
1616
1616
buf. push_str ( & format ! ( "{}" , field_name) ) ;
1617
1617
} else {
@@ -1650,66 +1650,65 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1650
1650
}
1651
1651
}
1652
1652
1653
- // FIXME Instead of passing usize, Field should be passed
1654
- // End-user visible description of the `field_index`nth field of `base`
1655
- 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 {
1656
1655
match * base {
1657
1656
Lvalue :: Local ( local) => {
1658
1657
let local = & self . mir . local_decls [ local] ;
1659
- self . describe_field_from_ty ( & local. ty , field_index )
1658
+ self . describe_field_from_ty ( & local. ty , field )
1660
1659
} ,
1661
1660
Lvalue :: Static ( ref static_) => {
1662
- self . describe_field_from_ty ( & static_. ty , field_index )
1661
+ self . describe_field_from_ty ( & static_. ty , field )
1663
1662
} ,
1664
1663
Lvalue :: Projection ( ref proj) => {
1665
1664
match proj. elem {
1666
1665
ProjectionElem :: Deref =>
1667
- self . describe_field ( & proj. base , field_index ) ,
1666
+ self . describe_field ( & proj. base , field ) ,
1668
1667
ProjectionElem :: Downcast ( def, variant_index) =>
1669
- format ! ( "{}" , def. variants[ variant_index] . fields[ field_index ] . name) ,
1668
+ format ! ( "{}" , def. variants[ variant_index] . fields[ field . index ( ) ] . name) ,
1670
1669
ProjectionElem :: Field ( _, field_type) =>
1671
- self . describe_field_from_ty ( & field_type, field_index ) ,
1670
+ self . describe_field_from_ty ( & field_type, field ) ,
1672
1671
ProjectionElem :: Index ( ..)
1673
1672
| ProjectionElem :: ConstantIndex { .. }
1674
1673
| ProjectionElem :: Subslice { .. } =>
1675
- format ! ( "{}" , self . describe_field( & proj. base, field_index ) ) ,
1674
+ format ! ( "{}" , self . describe_field( & proj. base, field ) ) ,
1676
1675
}
1677
1676
}
1678
1677
}
1679
1678
}
1680
1679
1681
1680
// End-user visible description of the `field_index`nth field of `ty`
1682
- 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 {
1683
1682
if ty. is_box ( ) {
1684
1683
// If the type is a box, the field is described from the boxed type
1685
- self . describe_field_from_ty ( & ty. boxed_ty ( ) , field_index )
1684
+ self . describe_field_from_ty ( & ty. boxed_ty ( ) , field )
1686
1685
}
1687
1686
else {
1688
1687
match ty. sty {
1689
1688
ty:: TyAdt ( def, _) => {
1690
1689
if def. is_enum ( ) {
1691
- format ! ( "{}" , field_index )
1690
+ format ! ( "{}" , field . index ( ) )
1692
1691
}
1693
1692
else {
1694
- format ! ( "{}" , def. struct_variant( ) . fields[ field_index ] . name)
1693
+ format ! ( "{}" , def. struct_variant( ) . fields[ field . index ( ) ] . name)
1695
1694
}
1696
1695
} ,
1697
1696
ty:: TyTuple ( _, _) => {
1698
- format ! ( "{}" , field_index )
1697
+ format ! ( "{}" , field . index ( ) )
1699
1698
} ,
1700
1699
ty:: TyRef ( _, tnm) | ty:: TyRawPtr ( tnm) => {
1701
- self . describe_field_from_ty ( & tnm. ty , field_index )
1700
+ self . describe_field_from_ty ( & tnm. ty , field )
1702
1701
} ,
1703
1702
ty:: TyArray ( ty, _) | ty:: TySlice ( ty) => {
1704
- self . describe_field_from_ty ( & ty, field_index )
1703
+ self . describe_field_from_ty ( & ty, field )
1705
1704
} ,
1706
1705
ty:: TyClosure ( closure_def_id, _) => {
1707
1706
// Convert the def-id into a node-id. node-ids are only valid for
1708
1707
// the local code in the current crate, so this returns an `Option` in case
1709
1708
// the closure comes from another crate. But in that case we wouldn't
1710
1709
// be borrowck'ing it, so we can just unwrap:
1711
1710
let node_id = self . tcx . hir . as_local_node_id ( closure_def_id) . unwrap ( ) ;
1712
- 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 ( ) ] ) ;
1713
1712
1714
1713
self . tcx . hir . name ( freevar. var_id ( ) ) . to_string ( )
1715
1714
}
0 commit comments