From 678e5a09970d735d96e4255ec2becd9797e7b4b5 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Fri, 26 Apr 2024 20:44:59 +0200 Subject: [PATCH] Add "safety" comment --- core/src/slice/raw.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/slice/raw.rs b/core/src/slice/raw.rs index d001688d79d80..8ff429218a4df 100644 --- a/core/src/slice/raw.rs +++ b/core/src/slice/raw.rs @@ -92,11 +92,16 @@ use crate::ub_checks; /// ``` /// use std::slice; /// +/// /// # Safety +/// /// +/// /// If ptr is not NULL, it must be correctly aligned and +/// /// point to `len` initialized items of type `f32`. /// unsafe extern "C" fn handle_slice(ptr: *const f32, len: usize) { /// let data = if ptr.is_null() { /// // `len` is assumed to be 0. /// &[] /// } else { +/// // SAFETY: see function docstring. /// unsafe { slice::from_raw_parts(ptr, len) } /// }; /// dbg!(data);