Skip to content

Commit b602bbf

Browse files
committed
Remove type safe MaybeUninit ptr conversion
Signed-off-by: Alex Saveau <[email protected]>
1 parent cc18694 commit b602bbf

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

compiler/rustc_serialize/src/opaque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl FileEncoder {
182182
// room to write the input to the buffer.
183183
unsafe {
184184
let src = buf.as_ptr();
185-
let dst = self.buf.as_mut_ptr().add(buffered).into_inner();
185+
let dst = self.buf.as_mut_ptr().add(buffered).cast::<u8>();
186186
ptr::copy_nonoverlapping(src, dst, buf_len);
187187
}
188188

library/core/src/fmt/num.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ unsafe trait GenericRadix: Sized {
106106
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
107107
// valid UTF-8
108108
let buf = unsafe {
109-
str::from_utf8_unchecked(slice::from_raw_parts(buf.as_ptr().into_inner(), buf.len()))
109+
str::from_utf8_unchecked(slice::from_raw_parts(buf.as_ptr().cast::<u8>(), buf.len()))
110110
};
111111
f.pad_integral(is_nonnegative, Self::PREFIX, buf)
112112
}
@@ -213,7 +213,7 @@ macro_rules! impl_Display {
213213
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
214214
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
215215
let mut curr = buf.len();
216-
let buf_ptr = buf.as_mut_ptr().into_inner();
216+
let buf_ptr = buf.as_mut_ptr().cast::<u8>();
217217
let lut_ptr = DEC_DIGITS_LUT.as_ptr();
218218

219219
// SAFETY: Since `d1` and `d2` are always less than or equal to `198`, we
@@ -341,7 +341,7 @@ macro_rules! impl_Exp {
341341
// that `curr >= 0`.
342342
let mut buf = [MaybeUninit::<u8>::uninit(); 40];
343343
let mut curr = buf.len(); //index for buf
344-
let buf_ptr = buf.as_mut_ptr().into_inner();
344+
let buf_ptr = buf.as_mut_ptr().cast::<u8>();
345345
let lut_ptr = DEC_DIGITS_LUT.as_ptr();
346346

347347
// decode 2 chars at a time
@@ -397,11 +397,11 @@ macro_rules! impl_Exp {
397397
} else {
398398
let off = exponent << 1;
399399
// SAFETY: 1 + 2 <= 3
400-
unsafe { ptr::copy_nonoverlapping(lut_ptr.add(off), exp_buf.as_mut_ptr().into_inner().add(1), 2); }
400+
unsafe { ptr::copy_nonoverlapping(lut_ptr.add(off), exp_buf.as_mut_ptr().add(1).cast::<u8>(), 2); }
401401
3
402402
};
403403
// SAFETY: max(2, 3) <= 3
404-
unsafe { slice::from_raw_parts(exp_buf.as_mut_ptr().into_inner(), len) }
404+
unsafe { slice::from_raw_parts(exp_buf.as_mut_ptr().cast::<u8>(), len) }
405405
};
406406

407407
let parts = &[
@@ -481,7 +481,7 @@ impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128);
481481

482482
/// Helper function for writing a u64 into `buf` going from last to first, with `curr`.
483483
fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], curr: &mut usize) {
484-
let buf_ptr = buf.as_mut_ptr().into_inner();
484+
let buf_ptr = buf.as_mut_ptr().cast::<u8>();
485485
let lut_ptr = DEC_DIGITS_LUT.as_ptr();
486486
assert!(*curr > 19);
487487

@@ -628,7 +628,7 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
628628
// UTF-8 since `DEC_DIGITS_LUT` is
629629
let buf_slice = unsafe {
630630
str::from_utf8_unchecked(slice::from_raw_parts(
631-
buf.as_mut_ptr().add(curr).into_inner(),
631+
buf.as_mut_ptr().add(curr).cast::<u8>(),
632632
buf.len() - curr,
633633
))
634634
};

library/core/src/mem/maybe_uninit.rs

-22
Original file line numberDiff line numberDiff line change
@@ -1294,25 +1294,3 @@ impl<T, const N: usize> [MaybeUninit<T>; N] {
12941294
unsafe { intrinsics::transmute_unchecked(self) }
12951295
}
12961296
}
1297-
1298-
impl<T> *const MaybeUninit<T> {
1299-
/// Converts a MaybeUninit pointer to its underlying type.
1300-
///
1301-
/// See [`MaybeUninit::as_ptr`] for caveats.
1302-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1303-
#[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")]
1304-
pub const fn into_inner(self) -> *const T {
1305-
self.cast()
1306-
}
1307-
}
1308-
1309-
impl<T> *mut MaybeUninit<T> {
1310-
/// Converts mutable a MaybeUninit pointer to its underlying type.
1311-
///
1312-
/// See [`MaybeUninit::as_mut_ptr`] for caveats.
1313-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1314-
#[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")]
1315-
pub const fn into_inner(self) -> *mut T {
1316-
self.cast()
1317-
}
1318-
}

library/core/src/slice/sort.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ where
376376

377377
if start_l == end_l {
378378
// Trace `block_l` elements from the left side.
379-
start_l = offsets_l.as_mut_ptr().into_inner();
379+
start_l = offsets_l.as_mut_ptr().cast::<u8>();
380380
end_l = start_l;
381381
let mut elem = l;
382382

@@ -402,7 +402,7 @@ where
402402

403403
if start_r == end_r {
404404
// Trace `block_r` elements from the right side.
405-
start_r = offsets_r.as_mut_ptr().into_inner();
405+
start_r = offsets_r.as_mut_ptr().cast::<u8>();
406406
end_r = start_r;
407407
let mut elem = r;
408408

0 commit comments

Comments
 (0)