Skip to content

Commit a3e2dbb

Browse files
committed
fix: avoid NonNull::slice_from_raw_parts for MSRV
1 parent bbc5349 commit a3e2dbb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/map.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -6580,7 +6580,15 @@ mod test_map_with_mmap_allocations {
65806580
}
65816581

65826582
match NonNull::new(addr.cast()) {
6583-
Some(addr) => Ok(NonNull::slice_from_raw_parts(addr, len)),
6583+
Some(data) => {
6584+
// SAFETY: this is NonNull::slice_from_raw_parts.
6585+
Ok(unsafe {
6586+
NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(
6587+
data.as_ptr(),
6588+
len,
6589+
))
6590+
})
6591+
}
65846592

65856593
// This branch shouldn't be taken in practice, but since we
65866594
// cannot return null as a valid pointer in our type system,

src/raw/alloc.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ mod inner {
7272
#[inline]
7373
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, ()> {
7474
match unsafe { NonNull::new(alloc(layout)) } {
75-
Some(ptr) => Ok(NonNull::slice_from_raw_parts(ptr, layout.size())),
75+
Some(data) => {
76+
// SAFETY: this is NonNull::slice_from_raw_parts.
77+
Ok(unsafe {
78+
NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(
79+
data.as_ptr(),
80+
len,
81+
))
82+
})
83+
}
7684
None => Err(()),
7785
}
7886
}

0 commit comments

Comments
 (0)