1010use std:: marker:: PhantomData ;
1111use std:: ops:: Range ;
1212
13- use rustc_abi:: { self as abi, Size , VariantIdx } ;
13+ use rustc_abi:: { self as abi, FieldIdx , Size , VariantIdx } ;
1414use rustc_middle:: ty:: Ty ;
1515use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
1616use rustc_middle:: { bug, mir, span_bug, ty} ;
@@ -144,22 +144,22 @@ where
144144 /// always possible without allocating, so it can take `&self`. Also return the field's layout.
145145 /// This supports both struct and array fields, but not slices!
146146 ///
147- /// This also works for arrays, but then the `usize ` index type is restricting.
148- /// For indexing into arrays, use `mplace_index` .
147+ /// This also works for arrays, but then the `FieldIdx ` index type is restricting.
148+ /// For indexing into arrays, use [`Self::project_index`] .
149149 pub fn project_field < P : Projectable < ' tcx , M :: Provenance > > (
150150 & self ,
151151 base : & P ,
152- field : usize ,
152+ field : FieldIdx ,
153153 ) -> InterpResult < ' tcx , P > {
154154 // Slices nominally have length 0, so they will panic somewhere in `fields.offset`.
155155 debug_assert ! (
156156 !matches!( base. layout( ) . ty. kind( ) , ty:: Slice ( ..) ) ,
157157 "`field` projection called on a slice -- call `index` projection instead"
158158 ) ;
159- let offset = base. layout ( ) . fields . offset ( field) ;
159+ let offset = base. layout ( ) . fields . offset ( field. as_usize ( ) ) ;
160160 // Computing the layout does normalization, so we get a normalized type out of this
161161 // even if the field type is non-normalized (possible e.g. via associated types).
162- let field_layout = base. layout ( ) . field ( self , field) ;
162+ let field_layout = base. layout ( ) . field ( self , field. as_usize ( ) ) ;
163163
164164 // Offset may need adjustment for unsized fields.
165165 let ( meta, offset) = if field_layout. is_unsized ( ) {
@@ -244,7 +244,7 @@ where
244244 }
245245 _ => span_bug ! (
246246 self . cur_span( ) ,
247- "`mplace_index ` called on non-array type {:?}" ,
247+ "`project_index ` called on non-array type {:?}" ,
248248 base. layout( ) . ty
249249 ) ,
250250 } ;
@@ -260,7 +260,7 @@ where
260260 ) -> InterpResult < ' tcx , ( P , u64 ) > {
261261 assert ! ( base. layout( ) . ty. ty_adt_def( ) . unwrap( ) . repr( ) . simd( ) ) ;
262262 // SIMD types must be newtypes around arrays, so all we have to do is project to their only field.
263- let array = self . project_field ( base, 0 ) ?;
263+ let array = self . project_field ( base, FieldIdx :: ZERO ) ?;
264264 let len = array. len ( self ) ?;
265265 interp_ok ( ( array, len) )
266266 }
@@ -384,7 +384,7 @@ where
384384 UnwrapUnsafeBinder ( target) => base. transmute ( self . layout_of ( target) ?, self ) ?,
385385 // We don't want anything happening here, this is here as a dummy.
386386 Subtype ( _) => base. transmute ( base. layout ( ) , self ) ?,
387- Field ( field, _) => self . project_field ( base, field. index ( ) ) ?,
387+ Field ( field, _) => self . project_field ( base, field) ?,
388388 Downcast ( _, variant) => self . project_downcast ( base, variant) ?,
389389 Deref => self . deref_pointer ( & base. to_op ( self ) ?) ?. into ( ) ,
390390 Index ( local) => {
0 commit comments