@@ -41,14 +41,14 @@ fn move_into_copy() {
41
41
let a = arr2 ( & [ [ 1. , 2. ] , [ 3. , 4. ] ] ) ;
42
42
let acopy = a. clone ( ) ;
43
43
let mut b = Array :: uninit ( a. dim ( ) ) ;
44
- a. move_into ( b. view_mut ( ) ) ;
44
+ a. move_into_uninit ( b. view_mut ( ) ) ;
45
45
let b = unsafe { b. assume_init ( ) } ;
46
46
assert_eq ! ( acopy, b) ;
47
47
48
48
let a = arr2 ( & [ [ 1. , 2. ] , [ 3. , 4. ] ] ) . reversed_axes ( ) ;
49
49
let acopy = a. clone ( ) ;
50
50
let mut b = Array :: uninit ( a. dim ( ) ) ;
51
- a. move_into ( b. view_mut ( ) ) ;
51
+ a. move_into_uninit ( b. view_mut ( ) ) ;
52
52
let b = unsafe { b. assume_init ( ) } ;
53
53
assert_eq ! ( acopy, b) ;
54
54
}
@@ -74,7 +74,7 @@ fn move_into_owned() {
74
74
75
75
let acopy = a. clone ( ) ;
76
76
let mut b = Array :: uninit ( a. dim ( ) ) ;
77
- a. move_into ( b. view_mut ( ) ) ;
77
+ a. move_into_uninit ( b. view_mut ( ) ) ;
78
78
let b = unsafe { b. assume_init ( ) } ;
79
79
80
80
assert_eq ! ( acopy, b) ;
@@ -85,7 +85,7 @@ fn move_into_owned() {
85
85
86
86
#[ test]
87
87
fn move_into_slicing ( ) {
88
- // Count correct number of drops when using move_into and discontiguous arrays (with holes).
88
+ // Count correct number of drops when using move_into_uninit and discontiguous arrays (with holes).
89
89
for & use_f_order in & [ false , true ] {
90
90
for & invert_axis in & [ 0b00 , 0b01 , 0b10 , 0b11 ] { // bitmask for axis to invert
91
91
let counter = DropCounter :: default ( ) ;
@@ -102,7 +102,7 @@ fn move_into_slicing() {
102
102
}
103
103
104
104
let mut b = Array :: uninit ( a. dim ( ) ) ;
105
- a. move_into ( b. view_mut ( ) ) ;
105
+ a. move_into_uninit ( b. view_mut ( ) ) ;
106
106
let b = unsafe { b. assume_init ( ) } ;
107
107
108
108
let total = m * n;
@@ -118,7 +118,7 @@ fn move_into_slicing() {
118
118
119
119
#[ test]
120
120
fn move_into_diag ( ) {
121
- // Count correct number of drops when using move_into and discontiguous arrays (with holes).
121
+ // Count correct number of drops when using move_into_uninit and discontiguous arrays (with holes).
122
122
for & use_f_order in & [ false , true ] {
123
123
let counter = DropCounter :: default ( ) ;
124
124
{
@@ -128,7 +128,7 @@ fn move_into_diag() {
128
128
let a = a. into_diag ( ) ;
129
129
130
130
let mut b = Array :: uninit ( a. dim ( ) ) ;
131
- a. move_into ( b. view_mut ( ) ) ;
131
+ a. move_into_uninit ( b. view_mut ( ) ) ;
132
132
let b = unsafe { b. assume_init ( ) } ;
133
133
134
134
let total = m * n;
@@ -143,7 +143,7 @@ fn move_into_diag() {
143
143
144
144
#[ test]
145
145
fn move_into_0dim ( ) {
146
- // Count correct number of drops when using move_into and discontiguous arrays (with holes).
146
+ // Count correct number of drops when using move_into_uninit and discontiguous arrays (with holes).
147
147
for & use_f_order in & [ false , true ] {
148
148
let counter = DropCounter :: default ( ) ;
149
149
{
@@ -155,7 +155,7 @@ fn move_into_0dim() {
155
155
156
156
assert_eq ! ( a. ndim( ) , 0 ) ;
157
157
let mut b = Array :: uninit ( a. dim ( ) ) ;
158
- a. move_into ( b. view_mut ( ) ) ;
158
+ a. move_into_uninit ( b. view_mut ( ) ) ;
159
159
let b = unsafe { b. assume_init ( ) } ;
160
160
161
161
let total = m * n;
@@ -170,7 +170,7 @@ fn move_into_0dim() {
170
170
171
171
#[ test]
172
172
fn move_into_empty ( ) {
173
- // Count correct number of drops when using move_into and discontiguous arrays (with holes).
173
+ // Count correct number of drops when using move_into_uninit and discontiguous arrays (with holes).
174
174
for & use_f_order in & [ false , true ] {
175
175
let counter = DropCounter :: default ( ) ;
176
176
{
@@ -181,7 +181,7 @@ fn move_into_empty() {
181
181
let a = a. slice_move ( s ! [ ..0 , 1 ..1 ] ) ;
182
182
assert ! ( a. is_empty( ) ) ;
183
183
let mut b = Array :: uninit ( a. dim ( ) ) ;
184
- a. move_into ( b. view_mut ( ) ) ;
184
+ a. move_into_uninit ( b. view_mut ( ) ) ;
185
185
let b = unsafe { b. assume_init ( ) } ;
186
186
187
187
let total = m * n;
@@ -194,6 +194,35 @@ fn move_into_empty() {
194
194
}
195
195
}
196
196
197
+ #[ test]
198
+ fn move_into ( ) {
199
+ // Test various memory layouts and holes while moving String elements with move_into
200
+ for & use_f_order in & [ false , true ] {
201
+ for & invert_axis in & [ 0b00 , 0b01 , 0b10 , 0b11 ] { // bitmask for axis to invert
202
+ for & slice in & [ false , true ] {
203
+ let mut a = Array :: from_shape_fn ( ( 5 , 4 ) . set_f ( use_f_order) ,
204
+ |idx| format ! ( "{:?}" , idx) ) ;
205
+ if slice {
206
+ a. slice_collapse ( s ! [ 1 ..-1 , ..; 2 ] ) ;
207
+ }
208
+
209
+ if invert_axis & 0b01 != 0 {
210
+ a. invert_axis ( Axis ( 0 ) ) ;
211
+ }
212
+ if invert_axis & 0b10 != 0 {
213
+ a. invert_axis ( Axis ( 1 ) ) ;
214
+ }
215
+
216
+ let acopy = a. clone ( ) ;
217
+ let mut b = Array :: default ( a. dim ( ) . set_f ( !use_f_order ^ !slice) ) ;
218
+ a. move_into ( & mut b) ;
219
+
220
+ assert_eq ! ( acopy, b) ;
221
+ }
222
+ }
223
+ }
224
+ }
225
+
197
226
198
227
/// This counter can create elements, and then count and verify
199
228
/// the number of which have actually been dropped again.
0 commit comments