@@ -1345,40 +1345,6 @@ pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
1345
1345
/// assert_eq!(x, [7, 8, 3, 4]);
1346
1346
/// assert_eq!(y, [1, 2, 9]);
1347
1347
/// ```
1348
- ///
1349
- /// # Const evaluation limitations
1350
- ///
1351
- /// If this function is invoked during const-evaluation, the current implementation has a small (and
1352
- /// rarely relevant) limitation: if `count` is at least 2 and the data pointed to by `x` or `y`
1353
- /// contains a pointer that crosses the boundary of two `T`-sized chunks of memory, the function may
1354
- /// fail to evaluate (similar to a panic during const-evaluation). This behavior may change in the
1355
- /// future.
1356
- ///
1357
- /// The limitation is illustrated by the following example:
1358
- ///
1359
- /// ```
1360
- /// use std::mem::size_of;
1361
- /// use std::ptr;
1362
- ///
1363
- /// const { unsafe {
1364
- /// const PTR_SIZE: usize = size_of::<*const i32>();
1365
- /// let mut data1 = [0u8; PTR_SIZE];
1366
- /// let mut data2 = [0u8; PTR_SIZE];
1367
- /// // Store a pointer in `data1`.
1368
- /// data1.as_mut_ptr().cast::<*const i32>().write_unaligned(&42);
1369
- /// // Swap the contents of `data1` and `data2` by swapping `PTR_SIZE` many `u8`-sized chunks.
1370
- /// // This call will fail, because the pointer in `data1` crosses the boundary
1371
- /// // between several of the 1-byte chunks that are being swapped here.
1372
- /// //ptr::swap_nonoverlapping(data1.as_mut_ptr(), data2.as_mut_ptr(), PTR_SIZE);
1373
- /// // Swap the contents of `data1` and `data2` by swapping a single chunk of size
1374
- /// // `[u8; PTR_SIZE]`. That works, as there is no pointer crossing the boundary between
1375
- /// // two chunks.
1376
- /// ptr::swap_nonoverlapping(&mut data1, &mut data2, 1);
1377
- /// // Read the pointer from `data2` and dereference it.
1378
- /// let ptr = data2.as_ptr().cast::<*const i32>().read_unaligned();
1379
- /// assert!(*ptr == 42);
1380
- /// } }
1381
- /// ```
1382
1348
#[ inline]
1383
1349
#[ stable( feature = "swap_nonoverlapping" , since = "1.27.0" ) ]
1384
1350
#[ rustc_const_stable( feature = "const_swap_nonoverlapping" , since = "1.88.0" ) ]
@@ -1407,9 +1373,7 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
1407
1373
const_eval_select ! (
1408
1374
@capture[ T ] { x: * mut T , y: * mut T , count: usize } :
1409
1375
if const {
1410
- // At compile-time we want to always copy this in chunks of `T`, to ensure that if there
1411
- // are pointers inside `T` we will copy them in one go rather than trying to copy a part
1412
- // of a pointer (which would not work).
1376
+ // At compile-time we don't need all the special code below.
1413
1377
// SAFETY: Same preconditions as this function
1414
1378
unsafe { swap_nonoverlapping_const( x, y, count) }
1415
1379
} else {
0 commit comments