@@ -7,7 +7,9 @@ use std::borrow::Cow;
7
7
use std:: cell:: Cell ;
8
8
use std:: collections:: TryReserveErrorKind :: * ;
9
9
use std:: fmt:: Debug ;
10
+ use std:: hint;
10
11
use std:: iter:: InPlaceIterable ;
12
+ use std:: mem;
11
13
use std:: mem:: { size_of, swap} ;
12
14
use std:: ops:: Bound :: * ;
13
15
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
@@ -1107,8 +1109,31 @@ fn test_into_iter_drop_allocator() {
1107
1109
1108
1110
#[ test]
1109
1111
fn test_into_iter_zst ( ) {
1110
- for _ in vec ! [ [ 0u64 ; 0 ] ] . into_iter ( ) { }
1111
- for _ in vec ! [ [ 0u64 ; 0 ] ; 5 ] . into_iter ( ) . rev ( ) { }
1112
+ #[ derive( Debug , Clone ) ]
1113
+ struct AlignedZstWithDrop ( [ u64 ; 0 ] ) ;
1114
+ impl Drop for AlignedZstWithDrop {
1115
+ fn drop ( & mut self ) {
1116
+ let addr = self as * mut _ as usize ;
1117
+ assert ! ( hint:: black_box( addr) % mem:: align_of:: <u64 >( ) == 0 ) ;
1118
+ }
1119
+ }
1120
+
1121
+ const C : AlignedZstWithDrop = AlignedZstWithDrop ( [ 0u64 ; 0 ] ) ;
1122
+
1123
+ for _ in vec ! [ C ] . into_iter ( ) { }
1124
+ for _ in vec ! [ C ; 5 ] . into_iter ( ) . rev ( ) { }
1125
+
1126
+ let mut it = vec ! [ C , C ] . into_iter ( ) ;
1127
+ it. advance_by ( 1 ) . unwrap ( ) ;
1128
+ drop ( it) ;
1129
+
1130
+ let mut it = vec ! [ C , C ] . into_iter ( ) ;
1131
+ it. next_chunk :: < 1 > ( ) . unwrap ( ) ;
1132
+ drop ( it) ;
1133
+
1134
+ let mut it = vec ! [ C , C ] . into_iter ( ) ;
1135
+ it. next_chunk :: < 4 > ( ) . unwrap_err ( ) ;
1136
+ drop ( it) ;
1112
1137
}
1113
1138
1114
1139
#[ test]
0 commit comments