Rollup merge of #142205 - paolobarbolini:const_swap_with_slice-impl, r=Mark-Simulacrum

Mark `slice::swap_with_slice` unstably const

Tracking issue rust-lang/rust#142204
This commit is contained in:
Stuart Cook
2025-08-04 11:24:35 +10:00
committed by GitHub

View File

@@ -3974,8 +3974,9 @@ impl<T> [T] {
///
/// [`split_at_mut`]: slice::split_at_mut
#[stable(feature = "swap_with_slice", since = "1.27.0")]
#[rustc_const_unstable(feature = "const_swap_with_slice", issue = "142204")]
#[track_caller]
pub fn swap_with_slice(&mut self, other: &mut [T]) {
pub const fn swap_with_slice(&mut self, other: &mut [T]) {
assert!(self.len() == other.len(), "destination and source slices have different lengths");
// SAFETY: `self` is valid for `self.len()` elements by definition, and `src` was
// checked to have the same length. The slices cannot overlap because