Skip to content

Commit efcd607

Browse files
committed
FIX: Make Partial::new an unsafe method
1 parent e3ebf8c commit efcd607

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/parallel/impl_par_methods.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ macro_rules! zip_impl {
100100
// Create a partial result for the contiguous slice of data being written to
101101
let output = zip.last_producer();
102102
debug_assert!(output.is_contiguous());
103-
104-
let mut partial = Partial::new(output.as_ptr());
103+
let mut partial;
104+
unsafe {
105+
partial = Partial::new(output.as_ptr());
106+
}
105107

106108
// Apply the mapping function on this chunk of the zip
107109
let partial_len = &mut partial.len;
@@ -173,7 +175,12 @@ pub(crate) struct Partial<T> {
173175

174176
impl<T> Partial<T> {
175177
/// Create an empty partial for this data pointer
176-
pub(crate) fn new(ptr: *mut T) -> Self {
178+
///
179+
/// Safety: Unless ownership is released, the
180+
/// Partial acts as an owner of the slice of data (not the allocation);
181+
/// and will free the elements on drop; the pointer must be dereferenceable
182+
/// and the `len` elements following it valid.
183+
pub(crate) unsafe fn new(ptr: *mut T) -> Self {
177184
Self {
178185
ptr,
179186
len: 0,

0 commit comments

Comments
 (0)