about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-01-18 11:24:16 +0100
committerRalf Jung <post@ralfj.de>2021-01-18 11:24:48 +0100
commitdc04ceae710a432baa11ddb986541d89253279a4 (patch)
treecae65d65408c1d5e7a0bb9d3fb9863b125fdcce8
parent0677d9729318441a1cdb0c74812ec4140fa4d35f (diff)
downloadrust-dc04ceae710a432baa11ddb986541d89253279a4.tar.gz
rust-dc04ceae710a432baa11ddb986541d89253279a4.zip
use raw-ptr-addr-of for slice::swap
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/slice/mod.rs7
2 files changed, 4 insertions, 4 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index df8d9ff371f..263c6c9cf0f 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -126,6 +126,7 @@
 #![feature(auto_traits)]
 #![feature(or_patterns)]
 #![feature(prelude_import)]
+#![feature(raw_ref_macros)]
 #![feature(repr_simd, platform_intrinsics)]
 #![feature(rustc_attrs)]
 #![feature(simd_ffi)]
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index de8d7fc29dc..b06b6e93373 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -542,10 +542,9 @@ impl<T> [T] {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn swap(&mut self, a: usize, b: usize) {
-        // Can't take two mutable loans from one vector, so instead just cast
-        // them to their raw pointers to do the swap.
-        let pa: *mut T = &mut self[a];
-        let pb: *mut T = &mut self[b];
+        // Can't take two mutable loans from one vector, so instead use raw pointers.
+        let pa = ptr::raw_mut!(self[a]);
+        let pb = ptr::raw_mut!(self[b]);
         // SAFETY: `pa` and `pb` have been created from safe mutable references and refer
         // to elements in the slice and therefore are guaranteed to be valid and aligned.
         // Note that accessing the elements behind `a` and `b` is checked and will