Skip to content

Commit 678e5a0

Browse files
committed
Add "safety" comment
1 parent 08f761f commit 678e5a0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/src/slice/raw.rs

+5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,16 @@ use crate::ub_checks;
9292
/// ```
9393
/// use std::slice;
9494
///
95+
/// /// # Safety
96+
/// ///
97+
/// /// If ptr is not NULL, it must be correctly aligned and
98+
/// /// point to `len` initialized items of type `f32`.
9599
/// unsafe extern "C" fn handle_slice(ptr: *const f32, len: usize) {
96100
/// let data = if ptr.is_null() {
97101
/// // `len` is assumed to be 0.
98102
/// &[]
99103
/// } else {
104+
/// // SAFETY: see function docstring.
100105
/// unsafe { slice::from_raw_parts(ptr, len) }
101106
/// };
102107
/// dbg!(data);

0 commit comments

Comments
 (0)