diff options
| author | Ralf Jung <post@ralfj.de> | 2024-11-30 10:04:41 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-11-30 10:42:17 +0100 |
| commit | 2a05e5be4f09503e0d33123bbf2b4343872d1162 (patch) | |
| tree | d95fd7cd8687c5df0d2cbfc7cbe697126d94e18c | |
| parent | ede5f0111d21b52f3f821455512d5c5b13fe9e29 (diff) | |
| download | rust-2a05e5be4f09503e0d33123bbf2b4343872d1162.tar.gz rust-2a05e5be4f09503e0d33123bbf2b4343872d1162.zip | |
add test for bytewise ptr::swap of a pointer
| -rw-r--r-- | library/core/tests/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/tests/ptr.rs | 19 | ||||
| -rw-r--r-- | tests/ui/consts/missing_span_in_backtrace.rs | 2 |
3 files changed, 21 insertions, 1 deletions
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 40129619ce5..29de66852a4 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -18,6 +18,7 @@ #![feature(const_eval_select)] #![feature(const_heap)] #![feature(const_nonnull_new)] +#![feature(const_swap)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] #![feature(core_io_borrowed_buf)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 91f8c977d08..7e9773f2fb9 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -898,6 +898,25 @@ fn test_const_copy() { } #[test] +fn test_const_swap() { + const { + let mut ptr1 = &1; + let mut ptr2 = &666; + + // Swap ptr1 and ptr2, bytewise. `swap` does not take a count + // so the best we can do is use an array. + type T = [u8; mem::size_of::<&i32>()]; + unsafe { + ptr::swap(ptr::from_mut(&mut ptr1).cast::<T>(), ptr::from_mut(&mut ptr2).cast::<T>()); + } + + // Make sure they still work. + assert!(*ptr1 == 666); + assert!(*ptr2 == 1); + }; +} + +#[test] fn test_null_array_as_slice() { let arr: *mut [u8; 4] = null_mut(); let ptr: *mut [u8] = arr.as_mut_slice(); diff --git a/tests/ui/consts/missing_span_in_backtrace.rs b/tests/ui/consts/missing_span_in_backtrace.rs index ea457c96f15..703cc7fbf89 100644 --- a/tests/ui/consts/missing_span_in_backtrace.rs +++ b/tests/ui/consts/missing_span_in_backtrace.rs @@ -1,7 +1,7 @@ //@ compile-flags: -Z ui-testing=no -#![feature(const_swap)] +#![feature(const_swap_nonoverlapping)] use std::{ mem::{self, MaybeUninit}, ptr, |
