Skip to content

Commit 612ddf0

Browse files
committed
Constify intrinsics::copy[_nonoverlapping]
1 parent ab88dd2 commit 612ddf0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/src/intrinsics.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,20 +1846,22 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -
18461846
/// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
18471847
#[doc(alias = "memcpy")]
18481848
#[stable(feature = "rust1", since = "1.0.0")]
1849+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "none")]
18491850
#[inline]
1850-
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
1851+
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
18511852
extern "rust-intrinsic" {
18521853
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
18531854
}
18541855

1855-
if cfg!(debug_assertions)
1856+
// FIXME: Perform these checks only at run time
1857+
/*if cfg!(debug_assertions)
18561858
&& !(is_aligned_and_not_null(src)
18571859
&& is_aligned_and_not_null(dst)
18581860
&& is_nonoverlapping(src, dst, count))
18591861
{
18601862
// Not panicking to keep codegen impact smaller.
18611863
abort();
1862-
}
1864+
}*/
18631865

18641866
// SAFETY: the safety contract for `copy_nonoverlapping` must be
18651867
// upheld by the caller.
@@ -1928,16 +1930,19 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
19281930
/// ```
19291931
#[doc(alias = "memmove")]
19301932
#[stable(feature = "rust1", since = "1.0.0")]
1933+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "none")]
19311934
#[inline]
1932-
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
1935+
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
19331936
extern "rust-intrinsic" {
1937+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "none")]
19341938
fn copy<T>(src: *const T, dst: *mut T, count: usize);
19351939
}
19361940

1937-
if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
1941+
// FIXME: Perform these checks only at run time
1942+
/*if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
19381943
// Not panicking to keep codegen impact smaller.
19391944
abort();
1940-
}
1945+
}*/
19411946

19421947
// SAFETY: the safety contract for `copy` must be upheld by the caller.
19431948
unsafe { copy(src, dst, count) }

0 commit comments

Comments
 (0)