Skip to content

Commit b515bb3

Browse files
committed
Rollup merge of #31999 - bluss:fundamental-raw-ptr, r=eddyb
Use raw pointer casts for slice, str's .as_ptr() We can now use raw pointer casts `*const [T] as *const T` and `*const str as *const u8` instead of .repr() for getting the pointer out of a slice.
2 parents fe56595 + 63c4065 commit b515bb3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/libcore/slice.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ impl<T> SliceExt for [T] {
285285

286286
#[inline]
287287
unsafe fn get_unchecked(&self, index: usize) -> &T {
288-
&*(self.repr().data.offset(index as isize))
288+
&*(self.as_ptr().offset(index as isize))
289289
}
290290

291291
#[inline]
292292
fn as_ptr(&self) -> *const T {
293-
self.repr().data
293+
self as *const [T] as *const T
294294
}
295295

296296
fn binary_search_by<F>(&self, mut f: F) -> Result<usize, usize> where
@@ -448,12 +448,12 @@ impl<T> SliceExt for [T] {
448448

449449
#[inline]
450450
unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T {
451-
&mut *(self.repr().data as *mut T).offset(index as isize)
451+
&mut *self.as_mut_ptr().offset(index as isize)
452452
}
453453

454454
#[inline]
455455
fn as_mut_ptr(&mut self) -> *mut T {
456-
self.repr().data as *mut T
456+
self as *mut [T] as *mut T
457457
}
458458

459459
#[inline]

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ impl StrExt for str {
18941894

18951895
#[inline]
18961896
fn as_ptr(&self) -> *const u8 {
1897-
self.repr().data
1897+
self as *const str as *const u8
18981898
}
18991899

19001900
#[inline]

0 commit comments

Comments
 (0)