Open
Description
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
- Split out of Tracking Issue for const_swap #83163
- Resolve blocking issues
- Final comment period (FCP)1
- Stabilization PR
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.
Footnotes
Metadata
Metadata
Assignees
Labels
Category: An issue tracking the progress of sth. like the implementation of an RFCIssue: The decision needed by the team is conjectured to be easy; this does not imply nominationRelevant to the language team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.