File tree Expand file tree Collapse file tree 2 files changed +27
-27
lines changed Expand file tree Collapse file tree 2 files changed +27
-27
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,20 @@ where
155
155
}
156
156
}
157
157
158
+ // Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
159
+ // FIXME: replace with `utils::array_assume_init`
160
+ unsafe fn array_assume_init < T , const N : usize > ( array : [ MaybeUninit < T > ; N ] ) -> [ T ; N ] {
161
+ // SAFETY:
162
+ // * The caller guarantees that all elements of the array are initialized
163
+ // * `MaybeUninit<T>` and T are guaranteed to have the same layout
164
+ // * `MaybeUninit` does not drop, so there are no double-frees
165
+ // And thus the conversion is safe
166
+ let ret = unsafe { ( & array as * const _ as * const [ T ; N ] ) . read ( ) } ;
167
+ #[ allow( clippy:: forget_non_drop) ]
168
+ mem:: forget ( array) ;
169
+ ret
170
+ }
171
+
158
172
#[ cfg( test) ]
159
173
mod tests {
160
174
use crate :: stream:: Zip ;
@@ -176,17 +190,3 @@ mod tests {
176
190
} )
177
191
}
178
192
}
179
-
180
- // Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
181
- // FIXME: replace with `utils::array_assume_init`
182
- unsafe fn array_assume_init < T , const N : usize > ( array : [ MaybeUninit < T > ; N ] ) -> [ T ; N ] {
183
- // SAFETY:
184
- // * The caller guarantees that all elements of the array are initialized
185
- // * `MaybeUninit<T>` and T are guaranteed to have the same layout
186
- // * `MaybeUninit` does not drop, so there are no double-frees
187
- // And thus the conversion is safe
188
- let ret = unsafe { ( & array as * const _ as * const [ T ; N ] ) . read ( ) } ;
189
- #[ allow( clippy:: forget_non_drop) ]
190
- mem:: forget ( array) ;
191
- ret
192
- }
Original file line number Diff line number Diff line change @@ -160,6 +160,19 @@ where
160
160
}
161
161
}
162
162
163
+ // Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
164
+ // FIXME: replace with `utils::array_assume_init`
165
+ unsafe fn vec_assume_init < T > ( vec : Vec < MaybeUninit < T > > ) -> Vec < T > {
166
+ // SAFETY:
167
+ // * The caller guarantees that all elements of the vec are initialized
168
+ // * `MaybeUninit<T>` and T are guaranteed to have the same layout
169
+ // * `MaybeUninit` does not drop, so there are no double-frees
170
+ // And thus the conversion is safe
171
+ let ret = unsafe { ( & vec as * const _ as * const Vec < T > ) . read ( ) } ;
172
+ mem:: forget ( vec) ;
173
+ ret
174
+ }
175
+
163
176
#[ cfg( test) ]
164
177
mod tests {
165
178
use alloc:: vec;
@@ -183,16 +196,3 @@ mod tests {
183
196
} )
184
197
}
185
198
}
186
-
187
- // Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
188
- // FIXME: replace with `utils::array_assume_init`
189
- unsafe fn vec_assume_init < T > ( vec : Vec < MaybeUninit < T > > ) -> Vec < T > {
190
- // SAFETY:
191
- // * The caller guarantees that all elements of the vec are initialized
192
- // * `MaybeUninit<T>` and T are guaranteed to have the same layout
193
- // * `MaybeUninit` does not drop, so there are no double-frees
194
- // And thus the conversion is safe
195
- let ret = unsafe { ( & vec as * const _ as * const Vec < T > ) . read ( ) } ;
196
- mem:: forget ( vec) ;
197
- ret
198
- }
You can’t perform that action at this time.
0 commit comments