10
10
use std:: marker:: PhantomData ;
11
11
use std:: ops:: Range ;
12
12
13
- use rustc_abi:: { self as abi, Size , VariantIdx } ;
13
+ use rustc_abi:: { self as abi, FieldIdx , Size , VariantIdx } ;
14
14
use rustc_middle:: ty:: Ty ;
15
15
use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
16
16
use rustc_middle:: { bug, mir, span_bug, ty} ;
@@ -144,22 +144,22 @@ where
144
144
/// always possible without allocating, so it can take `&self`. Also return the field's layout.
145
145
/// This supports both struct and array fields, but not slices!
146
146
///
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`] .
149
149
pub fn project_field < P : Projectable < ' tcx , M :: Provenance > > (
150
150
& self ,
151
151
base : & P ,
152
- field : usize ,
152
+ field : FieldIdx ,
153
153
) -> InterpResult < ' tcx , P > {
154
154
// Slices nominally have length 0, so they will panic somewhere in `fields.offset`.
155
155
debug_assert ! (
156
156
!matches!( base. layout( ) . ty. kind( ) , ty:: Slice ( ..) ) ,
157
157
"`field` projection called on a slice -- call `index` projection instead"
158
158
) ;
159
- let offset = base. layout ( ) . fields . offset ( field) ;
159
+ let offset = base. layout ( ) . fields . offset ( field. as_usize ( ) ) ;
160
160
// Computing the layout does normalization, so we get a normalized type out of this
161
161
// 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 ( ) ) ;
163
163
164
164
// Offset may need adjustment for unsized fields.
165
165
let ( meta, offset) = if field_layout. is_unsized ( ) {
@@ -244,7 +244,7 @@ where
244
244
}
245
245
_ => span_bug ! (
246
246
self . cur_span( ) ,
247
- "`mplace_index ` called on non-array type {:?}" ,
247
+ "`project_index ` called on non-array type {:?}" ,
248
248
base. layout( ) . ty
249
249
) ,
250
250
} ;
@@ -260,7 +260,7 @@ where
260
260
) -> InterpResult < ' tcx , ( P , u64 ) > {
261
261
assert ! ( base. layout( ) . ty. ty_adt_def( ) . unwrap( ) . repr( ) . simd( ) ) ;
262
262
// 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 ) ?;
264
264
let len = array. len ( self ) ?;
265
265
interp_ok ( ( array, len) )
266
266
}
@@ -384,7 +384,7 @@ where
384
384
UnwrapUnsafeBinder ( target) => base. transmute ( self . layout_of ( target) ?, self ) ?,
385
385
// We don't want anything happening here, this is here as a dummy.
386
386
Subtype ( _) => base. transmute ( base. layout ( ) , self ) ?,
387
- Field ( field, _) => self . project_field ( base, field. index ( ) ) ?,
387
+ Field ( field, _) => self . project_field ( base, field) ?,
388
388
Downcast ( _, variant) => self . project_downcast ( base, variant) ?,
389
389
Deref => self . deref_pointer ( & base. to_op ( self ) ?) ?. into ( ) ,
390
390
Index ( local) => {
0 commit comments