Skip to content

Commit d2850ab

Browse files
replace fn's after mod test
1 parent f8d5a64 commit d2850ab

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/stream/zip/array.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ where
155155
}
156156
}
157157

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+
158172
#[cfg(test)]
159173
mod tests {
160174
use crate::stream::Zip;
@@ -176,17 +190,3 @@ mod tests {
176190
})
177191
}
178192
}
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-
}

src/stream/zip/vec.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ where
160160
}
161161
}
162162

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+
163176
#[cfg(test)]
164177
mod tests {
165178
use alloc::vec;
@@ -183,16 +196,3 @@ mod tests {
183196
})
184197
}
185198
}
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-
}

0 commit comments

Comments
 (0)