Skip to content

Commit 3b4fe4a

Browse files
committed
Disable from_raw_parts
1 parent 3ef4a60 commit 3b4fe4a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

library/core/src/intrinsics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2648,12 +2648,13 @@ pub(crate) use assert_unsafe_precondition;
26482648
/// `align_of::<T>()`.
26492649
#[inline]
26502650
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
2651-
let mask = crate::mem::align_of::<T>() - 1;
2651+
let mask = const { crate::mem::align_of::<T>() - 1 };
26522652
let is_aligned = (ptr.addr() & mask) == 0;
26532653
let not_null = ptr.addr() != 0;
26542654
is_aligned && not_null
26552655
}
26562656

2657+
/*
26572658
/// Checks whether an allocation of `len` instances of `T` exceeds
26582659
/// the maximum allowed allocation size.
26592660
#[inline]
@@ -2664,6 +2665,7 @@ pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
26642665
};
26652666
len <= max_len
26662667
}
2668+
*/
26672669

26682670
/// Checks whether the regions of memory starting at `src` and `dst` of size
26692671
/// `count * size_of::<T>()` do *not* overlap.

library/core/src/slice/raw.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Free functions to create `&[T]` and `&mut [T]`.
22
33
use crate::array;
4+
/*
45
use crate::intrinsics::{
56
assert_unsafe_precondition, is_aligned_and_not_null, is_valid_allocation_size,
67
};
8+
*/
79
use crate::ops::Range;
810
use crate::ptr;
911

@@ -94,11 +96,13 @@ use crate::ptr;
9496
pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
9597
// SAFETY: the caller must uphold the safety contract for `from_raw_parts`.
9698
unsafe {
99+
/*
97100
assert_unsafe_precondition!(
98101
"slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`",
99102
[T](data: *const T, len: usize) => is_aligned_and_not_null(data)
100103
&& is_valid_allocation_size::<T>(len)
101104
);
105+
*/
102106
&*ptr::slice_from_raw_parts(data, len)
103107
}
104108
}
@@ -141,11 +145,13 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
141145
pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
142146
// SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`.
143147
unsafe {
148+
/*
144149
assert_unsafe_precondition!(
145150
"slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`",
146151
[T](data: *mut T, len: usize) => is_aligned_and_not_null(data)
147152
&& is_valid_allocation_size::<T>(len)
148153
);
154+
*/
149155
&mut *ptr::slice_from_raw_parts_mut(data, len)
150156
}
151157
}

0 commit comments

Comments
 (0)