Feature gate: #![feature(const_swap_nonoverlapping)]
This is a tracking issue for making swap_nonoverlapping a const fn.
Public API
mod ptr {
pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize);
}
Steps / History
Blocking Issues
ptr::swap_nonoverlapping has a limitation currently where it can fail when the data-to-swap contains pointers that cross the "element boundary" of such a swap (i.e., count > 1 and the pointer straddles the boundary between two T). Here's an example of code that unexpectedly fails:
const {
let mut ptr1 = &1;
let mut ptr2 = &666;
// Swap ptr1 and ptr2, bytewise.
unsafe {
ptr::swap_nonoverlapping(
ptr::from_mut(&mut ptr1).cast::<u8>(),
ptr::from_mut(&mut ptr2).cast::<u8>(),
mem::size_of::<&i32>(),
);
}
// Make sure they still work.
assert!(*ptr1 == 666);
assert!(*ptr2 == 1);
};
The proper way to fix this is to implement rust-lang/const-eval#72.
Feature gate:
#![feature(const_swap_nonoverlapping)]This is a tracking issue for making
swap_nonoverlappingaconst fn.Public API
Steps / History
Blocking Issues
ptr::swap_nonoverlappinghas a limitation currently where it can fail when the data-to-swap contains pointers that cross the "element boundary" of such a swap (i.e.,count > 1and the pointer straddles the boundary between twoT). Here's an example of code that unexpectedly fails:The proper way to fix this is to implement rust-lang/const-eval#72.
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩