Skip to content

Commit d425410

Browse files
okanecogitbot
authored and
gitbot
committed
Mark slice::copy_from_slice unstably const
1 parent b6b16bf commit d425410

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/src/slice/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::intrinsics::{exact_div, select_unpredictable, unchecked_sub};
1111
use crate::mem::{self, SizedTypeProperties};
1212
use crate::num::NonZero;
1313
use crate::ops::{Bound, OneSidedRange, Range, RangeBounds, RangeInclusive};
14+
use crate::panic::const_panic;
1415
use crate::simd::{self, Simd};
1516
use crate::ub_checks::assert_unsafe_precondition;
1617
use crate::{fmt, hint, ptr, range, slice};
@@ -3703,8 +3704,9 @@ impl<T> [T] {
37033704
/// [`split_at_mut`]: slice::split_at_mut
37043705
#[doc(alias = "memcpy")]
37053706
#[stable(feature = "copy_from_slice", since = "1.9.0")]
3707+
#[rustc_const_unstable(feature = "const_copy_from_slice", issue = "131415")]
37063708
#[track_caller]
3707-
pub fn copy_from_slice(&mut self, src: &[T])
3709+
pub const fn copy_from_slice(&mut self, src: &[T])
37083710
where
37093711
T: Copy,
37103712
{
@@ -3713,11 +3715,13 @@ impl<T> [T] {
37133715
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
37143716
#[cfg_attr(feature = "panic_immediate_abort", inline)]
37153717
#[track_caller]
3716-
fn len_mismatch_fail(dst_len: usize, src_len: usize) -> ! {
3717-
panic!(
3718-
"source slice length ({}) does not match destination slice length ({})",
3719-
src_len, dst_len,
3720-
);
3718+
const fn len_mismatch_fail(dst_len: usize, src_len: usize) -> ! {
3719+
const_panic!(
3720+
"copy_from_slice: source slice length does not match destination slice length",
3721+
"copy_from_slice: source slice length ({src_len}) does not match destination slice length ({dst_len})",
3722+
src_len: usize,
3723+
dst_len: usize,
3724+
)
37213725
}
37223726

37233727
if self.len() != src.len() {

0 commit comments

Comments
 (0)