Skip to content

Commit fd89470

Browse files
committed
Document that CStr::as_ptr returns a type alias
Workaround for #15823
1 parent af3c8b2 commit fd89470

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/core/src/ffi/c_str.rs

+5
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ impl CStr {
457457
/// to a contiguous region of memory terminated with a 0 byte to represent
458458
/// the end of the string.
459459
///
460+
/// The type of the returned pointer is
461+
/// [`*const c_char`][crate::ffi::c_char], and whether it's
462+
/// an alias for `*const i8` or `*const u8` is platform-specific.
463+
///
460464
/// **WARNING**
461465
///
462466
/// The returned pointer is read-only; writing to it (including passing it
@@ -470,6 +474,7 @@ impl CStr {
470474
/// # #![allow(unused_must_use)] #![allow(temporary_cstring_as_ptr)]
471475
/// use std::ffi::CString;
472476
///
477+
/// // Do not do this:
473478
/// let ptr = CString::new("Hello").expect("CString::new failed").as_ptr();
474479
/// unsafe {
475480
/// // `ptr` is dangling

0 commit comments

Comments
 (0)