@@ -587,12 +587,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
587587 // padding.
588588 match tys. kind {
589589 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- }
596590 _ => false ,
597591 }
598592 } =>
@@ -609,11 +603,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
609603 }
610604 // This is the element type size.
611605 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- }
617606 // This is the size in bytes of the whole array.
618607 let size = layout. size * len;
619608 // Size is not 0, get a pointer.
@@ -656,6 +645,13 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
656645 }
657646 }
658647 }
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+ }
659655 _ => {
660656 self . walk_aggregate ( op, fields) ? // default handler
661657 }
0 commit comments