@@ -731,38 +731,6 @@ pub const fn swap<T>(x: &mut T, y: &mut T) {
731
731
unsafe { intrinsics:: typed_swap ( x, y) }
732
732
}
733
733
734
- /// Same as [`swap`] semantically, but always uses the simple implementation.
735
- ///
736
- /// Used elsewhere in `mem` and `ptr` at the bottom layer of calls.
737
- #[ rustc_const_unstable( feature = "const_swap" , issue = "83163" ) ]
738
- #[ inline]
739
- pub ( crate ) const fn swap_simple < T > ( x : & mut T , y : & mut T ) {
740
- // We arrange for this to typically be called with small types,
741
- // so this reads-and-writes approach is actually better than using
742
- // copy_nonoverlapping as it easily puts things in LLVM registers
743
- // directly and doesn't end up inlining allocas.
744
- // And LLVM actually optimizes it to 3×memcpy if called with
745
- // a type larger than it's willing to keep in a register.
746
- // Having typed reads and writes in MIR here is also good as
747
- // it lets Miri and CTFE understand them better, including things
748
- // like enforcing type validity for them.
749
- // Importantly, read+copy_nonoverlapping+write introduces confusing
750
- // asymmetry to the behaviour where one value went through read+write
751
- // whereas the other was copied over by the intrinsic (see #94371).
752
- // Furthermore, using only read+write here benefits limited backends
753
- // such as SPIR-V that work on an underlying *typed* view of memory,
754
- // and thus have trouble with Rust's untyped memory operations.
755
-
756
- // SAFETY: exclusive references are always valid to read/write,
757
- // including being aligned, and nothing here panics so it's drop-safe.
758
- unsafe {
759
- let a = ptr:: read ( x) ;
760
- let b = ptr:: read ( y) ;
761
- ptr:: write ( x, b) ;
762
- ptr:: write ( y, a) ;
763
- }
764
- }
765
-
766
734
/// Replaces `dest` with the default value of `T`, returning the previous `dest` value.
767
735
///
768
736
/// * If you want to replace the values of two variables, see [`swap`].
0 commit comments