@@ -14,7 +14,7 @@ use rustc_hir as hir;
1414use rustc_hir:: def:: DefKind ;
1515use rustc_hir:: def_id:: LocalDefId ;
1616use rustc_hir:: lang_items:: LangItem ;
17- use rustc_index:: vec:: IndexVec ;
17+ use rustc_index:: vec:: { IndexSlice , IndexVec } ;
1818use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
1919use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
2020use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
@@ -1716,7 +1716,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17161716 fn aggregate_field_ty (
17171717 & mut self ,
17181718 ak : & AggregateKind < ' tcx > ,
1719- field_index : usize ,
1719+ field_index : FieldIdx ,
17201720 location : Location ,
17211721 ) -> Result < Ty < ' tcx > , FieldAccessError > {
17221722 let tcx = self . tcx ( ) ;
@@ -1725,16 +1725,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17251725 AggregateKind :: Adt ( adt_did, variant_index, substs, _, active_field_index) => {
17261726 let def = tcx. adt_def ( adt_did) ;
17271727 let variant = & def. variant ( variant_index) ;
1728- let adj_field_index =
1729- FieldIdx :: from_usize ( active_field_index. unwrap_or ( field_index) ) ;
1728+ let adj_field_index = active_field_index. unwrap_or ( field_index) ;
17301729 if let Some ( field) = variant. fields . get ( adj_field_index) {
17311730 Ok ( self . normalize ( field. ty ( tcx, substs) , location) )
17321731 } else {
17331732 Err ( FieldAccessError :: OutOfRange { field_count : variant. fields . len ( ) } )
17341733 }
17351734 }
17361735 AggregateKind :: Closure ( _, substs) => {
1737- match substs. as_closure ( ) . upvar_tys ( ) . nth ( field_index) {
1736+ match substs. as_closure ( ) . upvar_tys ( ) . nth ( field_index. as_usize ( ) ) {
17381737 Some ( ty) => Ok ( ty) ,
17391738 None => Err ( FieldAccessError :: OutOfRange {
17401739 field_count : substs. as_closure ( ) . upvar_tys ( ) . count ( ) ,
@@ -1745,7 +1744,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17451744 // It doesn't make sense to look at a field beyond the prefix;
17461745 // these require a variant index, and are not initialized in
17471746 // aggregate rvalues.
1748- match substs. as_generator ( ) . prefix_tys ( ) . nth ( field_index) {
1747+ match substs. as_generator ( ) . prefix_tys ( ) . nth ( field_index. as_usize ( ) ) {
17491748 Some ( ty) => Ok ( ty) ,
17501749 None => Err ( FieldAccessError :: OutOfRange {
17511750 field_count : substs. as_generator ( ) . prefix_tys ( ) . count ( ) ,
@@ -2350,7 +2349,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23502349 body : & Body < ' tcx > ,
23512350 rvalue : & Rvalue < ' tcx > ,
23522351 aggregate_kind : & AggregateKind < ' tcx > ,
2353- operands : & [ Operand < ' tcx > ] ,
2352+ operands : & IndexSlice < FieldIdx , Operand < ' tcx > > ,
23542353 location : Location ,
23552354 ) {
23562355 let tcx = self . tcx ( ) ;
@@ -2362,16 +2361,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23622361 return ;
23632362 }
23642363
2365- for ( i, operand) in operands. iter ( ) . enumerate ( ) {
2364+ for ( i, operand) in operands. iter_enumerated ( ) {
23662365 let field_ty = match self . aggregate_field_ty ( aggregate_kind, i, location) {
23672366 Ok ( field_ty) => field_ty,
23682367 Err ( FieldAccessError :: OutOfRange { field_count } ) => {
23692368 span_mirbug ! (
23702369 self ,
23712370 rvalue,
23722371 "accessed field #{} but variant only has {}" ,
2373- i,
2374- field_count
2372+ i. as_u32 ( ) ,
2373+ field_count,
23752374 ) ;
23762375 continue ;
23772376 }
0 commit comments