@@ -396,33 +396,33 @@ where
396
396
field : u64 ,
397
397
) -> InterpResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
398
398
// Not using the layout method because we want to compute on u64
399
- let offset = match base. layout . fields {
399
+ let ( offset, field_layout ) = match base. layout . fields {
400
400
layout:: FieldPlacement :: Arbitrary { ref offsets, .. } => {
401
- offsets[ usize:: try_from ( field) . unwrap ( ) ]
401
+ let field = usize:: try_from ( field) . unwrap ( ) ;
402
+ ( offsets[ field] , base. layout . field ( self , field) ?)
402
403
}
403
404
layout:: FieldPlacement :: Array { stride, .. } => {
404
405
let len = base. len ( self ) ?;
405
406
if field >= len {
406
407
// This can only be reached in ConstProp and non-rustc-MIR.
407
408
throw_ub ! ( BoundsCheckFailed { len, index: field } ) ;
408
409
}
409
- Size :: mul ( stride, field) // `Size` multiplication is checked
410
+ // All fields have the same layout.
411
+ ( Size :: mul ( stride, field) , base. layout . field ( self , 9 ) ?)
410
412
}
411
413
layout:: FieldPlacement :: Union ( count) => {
414
+ let field = usize:: try_from ( field) . unwrap ( ) ;
412
415
assert ! (
413
- field < u64 :: try_from ( count) . unwrap ( ) ,
416
+ field < count,
414
417
"Tried to access field {} of union {:#?} with {} fields" ,
415
418
field,
416
419
base. layout,
417
420
count
418
421
) ;
419
422
// Offset is always 0
420
- Size :: from_bytes ( 0 )
423
+ ( Size :: from_bytes ( 0 ) , base . layout . field ( self , field ) ? )
421
424
}
422
425
} ;
423
- // the only way conversion can fail if is this is an array (otherwise we already panicked
424
- // above). In that case, all fields have the same layout.
425
- let field_layout = base. layout . field ( self , usize:: try_from ( field) . unwrap_or ( 0 ) ) ?;
426
426
427
427
// Offset may need adjustment for unsized fields.
428
428
let ( meta, offset) = if field_layout. is_unsized ( ) {
0 commit comments