@@ -587,12 +587,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
587
587
// padding.
588
588
match tys. kind {
589
589
ty:: Int ( ..) | ty:: Uint ( ..) | ty:: Float ( ..) => true ,
590
- ty:: Tuple ( tys) if tys. len ( ) == 0 => true ,
591
- ty:: Adt ( adt_def, _)
592
- if adt_def. is_struct ( ) && adt_def. all_fields ( ) . next ( ) . is_none ( ) =>
593
- {
594
- true
595
- }
596
590
_ => false ,
597
591
}
598
592
} =>
@@ -609,11 +603,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
609
603
}
610
604
// This is the element type size.
611
605
let layout = self . ecx . layout_of ( tys) ?;
612
- // Empty tuples and fieldless structs (the only ZSTs that allow reaching this code)
613
- // have no data to be checked.
614
- if layout. is_zst ( ) {
615
- return Ok ( ( ) ) ;
616
- }
617
606
// This is the size in bytes of the whole array.
618
607
let size = layout. size * len;
619
608
// Size is not 0, get a pointer.
@@ -656,6 +645,13 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
656
645
}
657
646
}
658
647
}
648
+ // Fast path for arrays and slices of ZSTs. We only need to check a single ZST element
649
+ // of an array and not all of them, because there's only a single value of a specific
650
+ // ZST type, so either validation fails for all elements or none.
651
+ ty:: Array ( tys, ..) | ty:: Slice ( tys) if self . ecx . layout_of ( tys) ?. is_zst ( ) => {
652
+ // Validate just the first element
653
+ self . walk_aggregate ( op, fields. take ( 1 ) ) ?
654
+ }
659
655
_ => {
660
656
self . walk_aggregate ( op, fields) ? // default handler
661
657
}
0 commit comments