@@ -182,7 +182,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
182
182
ty : Ty < ' tcx > ,
183
183
substs : & ' tcx Substs < ' tcx >
184
184
) -> EvalResult < ' tcx , Pointer > {
185
- let size = self . type_size_with_substs ( ty, substs) ;
185
+ let size = self . type_size_with_substs ( ty, substs) . expect ( "cannot alloc memory for unsized type" ) ;
186
186
let align = self . type_align_with_substs ( ty, substs) ;
187
187
self . memory . allocate ( size, align)
188
188
}
@@ -290,16 +290,21 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
290
290
self . tcx . normalize_associated_type ( & substituted)
291
291
}
292
292
293
- fn type_size ( & self , ty : Ty < ' tcx > ) -> usize {
293
+ fn type_size ( & self , ty : Ty < ' tcx > ) -> Option < usize > {
294
294
self . type_size_with_substs ( ty, self . substs ( ) )
295
295
}
296
296
297
297
fn type_align ( & self , ty : Ty < ' tcx > ) -> usize {
298
298
self . type_align_with_substs ( ty, self . substs ( ) )
299
299
}
300
300
301
- fn type_size_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> usize {
302
- self . type_layout_with_substs ( ty, substs) . size ( & self . tcx . data_layout ) . bytes ( ) as usize
301
+ fn type_size_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> Option < usize > {
302
+ let layout = self . type_layout_with_substs ( ty, substs) ;
303
+ if layout. is_unsized ( ) {
304
+ None
305
+ } else {
306
+ Some ( layout. size ( & self . tcx . data_layout ) . bytes ( ) as usize )
307
+ }
303
308
}
304
309
305
310
fn type_align_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> usize {
@@ -480,7 +485,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
480
485
481
486
Array { .. } => {
482
487
let elem_size = match dest_ty. sty {
483
- ty:: TyArray ( elem_ty, _) => self . type_size ( elem_ty) as u64 ,
488
+ ty:: TyArray ( elem_ty, _) => self . type_size ( elem_ty) . expect ( "array elements are sized" ) as u64 ,
484
489
_ => bug ! ( "tried to assign {:?} to non-array type {:?}" , kind, dest_ty) ,
485
490
} ;
486
491
let offsets = ( 0 ..) . map ( |i| i * elem_size) ;
@@ -534,7 +539,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
534
539
} else {
535
540
for operand in operands {
536
541
let operand_ty = self . operand_ty ( operand) ;
537
- assert_eq ! ( self . type_size( operand_ty) , 0 ) ;
542
+ assert_eq ! ( self . type_size( operand_ty) , Some ( 0 ) ) ;
538
543
}
539
544
let offset = self . nonnull_offset ( dest_ty, nndiscr, discrfield) ?;
540
545
@@ -576,7 +581,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
576
581
ty:: TyArray ( elem_ty, n) => ( elem_ty, n) ,
577
582
_ => bug ! ( "tried to assign array-repeat to non-array type {:?}" , dest_ty) ,
578
583
} ;
579
- let elem_size = self . type_size ( elem_ty) ;
584
+ let elem_size = self . type_size ( elem_ty) . expect ( "repeat element type must be sized" ) ;
580
585
let value = self . eval_operand ( operand) ?;
581
586
582
587
// FIXME(solson)
@@ -991,7 +996,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
991
996
let ( base_ptr, _) = base. to_ptr_and_extra ( ) ;
992
997
993
998
let ( elem_ty, len) = base. elem_ty_and_len ( base_ty) ;
994
- let elem_size = self . type_size ( elem_ty) ;
999
+ let elem_size = self . type_size ( elem_ty) . expect ( "slice element must be sized" ) ;
995
1000
let n_ptr = self . eval_operand ( operand) ?;
996
1001
let usize = self . tcx . types . usize ;
997
1002
let n = self . value_to_primval ( n_ptr, usize) ?
@@ -1007,7 +1012,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1007
1012
let ( base_ptr, _) = base. to_ptr_and_extra ( ) ;
1008
1013
1009
1014
let ( elem_ty, n) = base. elem_ty_and_len ( base_ty) ;
1010
- let elem_size = self . type_size ( elem_ty) ;
1015
+ let elem_size = self . type_size ( elem_ty) . expect ( "sequence element must be sized" ) ;
1011
1016
assert ! ( n >= min_length as u64 ) ;
1012
1017
1013
1018
let index = if from_end {
@@ -1026,7 +1031,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1026
1031
let ( base_ptr, _) = base. to_ptr_and_extra ( ) ;
1027
1032
1028
1033
let ( elem_ty, n) = base. elem_ty_and_len ( base_ty) ;
1029
- let elem_size = self . type_size ( elem_ty) ;
1034
+ let elem_size = self . type_size ( elem_ty) . expect ( "slice element must be sized" ) ;
1030
1035
assert ! ( ( from as u64 ) <= n - ( to as u64 ) ) ;
1031
1036
let ptr = base_ptr. offset ( from as isize * elem_size as isize ) ;
1032
1037
let extra = LvalueExtra :: Length ( n - to as u64 - from as u64 ) ;
@@ -1046,7 +1051,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1046
1051
}
1047
1052
1048
1053
fn copy ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
1049
- let size = self . type_size ( ty) ;
1054
+ let size = self . type_size ( ty) . expect ( "cannot copy from an unsized type" ) ;
1050
1055
let align = self . type_align ( ty) ;
1051
1056
self . memory . copy ( src, dest, size, align) ?;
1052
1057
Ok ( ( ) )
@@ -1512,7 +1517,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1512
1517
for ( i, ( src_f, dst_f) ) in iter {
1513
1518
let src_fty = monomorphize_field_ty ( self . tcx , src_f, substs_a) ;
1514
1519
let dst_fty = monomorphize_field_ty ( self . tcx , dst_f, substs_b) ;
1515
- if self . type_size ( dst_fty) == 0 {
1520
+ if self . type_size ( dst_fty) == Some ( 0 ) {
1516
1521
continue ;
1517
1522
}
1518
1523
let src_field_offset = self . get_field_offset ( src_ty, i) ?. bytes ( ) as isize ;
0 commit comments