Skip to content

Commit a9a396d

Browse files
committed
Auto merge of #81160 - RalfJung:swap, r=oli-obk
use raw-ptr-addr-of for slice::swap Fixes #80682
2 parents 202720b + dc04cea commit a9a396d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
#![feature(auto_traits)]
127127
#![feature(or_patterns)]
128128
#![feature(prelude_import)]
129+
#![feature(raw_ref_macros)]
129130
#![feature(repr_simd, platform_intrinsics)]
130131
#![feature(rustc_attrs)]
131132
#![feature(simd_ffi)]

library/core/src/slice/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,9 @@ impl<T> [T] {
542542
#[stable(feature = "rust1", since = "1.0.0")]
543543
#[inline]
544544
pub fn swap(&mut self, a: usize, b: usize) {
545-
// Can't take two mutable loans from one vector, so instead just cast
546-
// them to their raw pointers to do the swap.
547-
let pa: *mut T = &mut self[a];
548-
let pb: *mut T = &mut self[b];
545+
// Can't take two mutable loans from one vector, so instead use raw pointers.
546+
let pa = ptr::raw_mut!(self[a]);
547+
let pb = ptr::raw_mut!(self[b]);
549548
// SAFETY: `pa` and `pb` have been created from safe mutable references and refer
550549
// to elements in the slice and therefore are guaranteed to be valid and aligned.
551550
// Note that accessing the elements behind `a` and `b` is checked and will

0 commit comments

Comments
 (0)