@@ -277,6 +277,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
277
277
self . tcx . erase_regions ( & value)
278
278
}
279
279
280
+ /// Return the size and aligment of the value at the given type.
281
+ /// Note that the value does not matter if the type is sized. For unsized types,
282
+ /// the value has to be a fat pointer, and we only care about the "extra" data in it.
280
283
pub fn size_and_align_of_dst (
281
284
& mut self ,
282
285
ty : ty:: Ty < ' tcx > ,
@@ -286,7 +289,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
286
289
Ok ( ( size as u64 , self . type_align ( ty) ? as u64 ) )
287
290
} else {
288
291
match ty. sty {
289
- ty:: TyAdt ( def , substs ) => {
292
+ ty:: TyAdt ( .. ) | ty :: TyTuple ( .. ) => {
290
293
// First get the size of all statically known fields.
291
294
// Don't use type_of::sizing_type_of because that expects t to be sized,
292
295
// and it also rounds up to alignment, which we want to avoid,
@@ -309,9 +312,19 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
309
312
310
313
// Recurse to get the size of the dynamically sized field (must be
311
314
// the last field).
312
- let last_field = def. struct_variant ( ) . fields . last ( ) . unwrap ( ) ;
313
- let field_ty = self . field_ty ( substs, last_field) ;
314
- let ( unsized_size, unsized_align) = self . size_and_align_of_dst ( field_ty, value) ?;
315
+ let ( unsized_size, unsized_align) = match ty. sty {
316
+ ty:: TyAdt ( def, substs) => {
317
+ let last_field = def. struct_variant ( ) . fields . last ( ) . unwrap ( ) ;
318
+ let field_ty = self . field_ty ( substs, last_field) ;
319
+ self . size_and_align_of_dst ( field_ty, value) ?
320
+ }
321
+ ty:: TyTuple ( ref types, _) => {
322
+ let field_ty = types. last ( ) . unwrap ( ) ;
323
+ let field_ty = self . tcx . normalize_associated_type ( field_ty) ;
324
+ self . size_and_align_of_dst ( field_ty, value) ?
325
+ }
326
+ _ => bug ! ( "We already checked that we know this type" ) ,
327
+ } ;
315
328
316
329
// FIXME (#26403, #27023): We should be adding padding
317
330
// to `sized_size` (to accommodate the `unsized_align`
0 commit comments