18
18
//! * A [null] pointer is *never* valid, not even for accesses of [size zero][zst].
19
19
//! * All pointers (except for the null pointer) are valid for all operations of
20
20
//! [size zero][zst].
21
+ //! * For a pointer to be valid, it is necessary, but not always sufficient, that the pointer
22
+ //! be *dereferencable*: the memory range of the given size starting at the pointer must all be
23
+ //! within the bounds of a single allocated object. Note that in Rust,
24
+ //! every (stack-allocated) variable is considered a separate allocated object.
21
25
//! * All accesses performed by functions in this module are *non-atomic* in the sense
22
26
//! of [atomic operations] used to synchronize between threads. This means it is
23
27
//! undefined behavior to perform two concurrent accesses to the same location from different
@@ -221,10 +225,15 @@ pub(crate) struct FatPtr<T> {
221
225
pub ( crate ) len : usize ,
222
226
}
223
227
224
- /// Forms a slice from a pointer and a length.
228
+ /// Forms a raw slice from a pointer and a length.
225
229
///
226
230
/// The `len` argument is the number of **elements**, not the number of bytes.
227
231
///
232
+ /// This function is safe, but actually using the return value is unsafe.
233
+ /// See the documentation of [`from_raw_parts`] for slice safety requirements.
234
+ ///
235
+ /// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
236
+ ///
228
237
/// # Examples
229
238
///
230
239
/// ```rust
@@ -243,12 +252,16 @@ pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
243
252
unsafe { Repr { raw : FatPtr { data, len } } . rust }
244
253
}
245
254
246
- /// Performs the same functionality as [`from_raw_parts `], except that a
247
- /// mutable slice is returned.
255
+ /// Performs the same functionality as [`slice_from_raw_parts `], except that a
256
+ /// raw mutable slice is returned, as opposed to a raw immutable slice .
248
257
///
249
- /// See the documentation of [`from_raw_parts `] for more details.
258
+ /// See the documentation of [`slice_from_raw_parts `] for more details.
250
259
///
251
- /// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
260
+ /// This function is safe, but actually using the return value is unsafe.
261
+ /// See the documentation of [`from_raw_parts_mut`] for slice safety requirements.
262
+ ///
263
+ /// [`slice_from_raw_parts`]: fn.slice_from_raw_parts.html
264
+ /// [`from_raw_parts_mut`]: ../../std/slice/fn.from_raw_parts_mut.html
252
265
#[ inline]
253
266
#[ unstable( feature = "slice_from_raw_parts" , reason = "recently added" , issue = "36925" ) ]
254
267
pub fn slice_from_raw_parts_mut < T > ( data : * mut T , len : usize ) -> * mut [ T ] {
0 commit comments