diff options
| author | bors <bors@rust-lang.org> | 2025-04-27 10:52:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-04-27 10:52:46 +0000 |
| commit | 267cae5bdbd602dd13f3851b9c96ce93697e59a0 (patch) | |
| tree | 4bcd8dfe2227264d74ef9a61a3a4ab29f06db300 /library/alloc/src | |
| parent | 8947e167e58c5c4f23cae94585301f8eb90d93ea (diff) | |
| parent | aa5c6d44cf53d77b6e12984235782bb2045f0ad4 (diff) | |
| download | rust-267cae5bdbd602dd13f3851b9c96ce93697e59a0.tar.gz rust-267cae5bdbd602dd13f3851b9c96ce93697e59a0.zip | |
Auto merge of #140360 - matthiaskrgr:rollup-savbr84, r=matthiaskrgr
Rollup of 8 pull requests
Successful merges:
- #137439 (Stabilise `std::ffi::c_str`)
- #137714 (Update safety documentation for `CString::from_ptr` and `str::from_boxed_utf8_unchecked`)
- #139031 (Use char::is_whitespace directly in str::trim*)
- #139090 (fix docs for `Peekable::next_if{_eq}`)
- #140297 (Update example to use CStr::to_string_lossy)
- #140330 (Clarified bootstrap optimization "true" argument)
- #140339 (session: Cleanup `CanonicalizedPath::new`)
- #140346 (rustc_span: Some hygiene cleanups)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 13 | ||||
| -rw-r--r-- | library/alloc/src/ffi/mod.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/str.rs | 4 |
3 files changed, 15 insertions, 4 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index d5b19470e31..8b448a18402 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -351,9 +351,14 @@ impl CString { /// # Safety /// /// This should only ever be called with a pointer that was earlier - /// obtained by calling [`CString::into_raw`]. Other usage (e.g., trying to take - /// ownership of a string that was allocated by foreign code) is likely to lead - /// to undefined behavior or allocator corruption. + /// obtained by calling [`CString::into_raw`], and the memory it points to must not be accessed + /// through any other pointer during the lifetime of reconstructed `CString`. + /// Other usage (e.g., trying to take ownership of a string that was allocated by foreign code) + /// is likely to lead to undefined behavior or allocator corruption. + /// + /// This function does not validate ownership of the raw pointer's memory. + /// A double-free may occur if the function is called twice on the same raw pointer. + /// Additionally, the caller must ensure the pointer is not dangling. /// /// It should be noted that the length isn't just "recomputed," but that /// the recomputed length must match the original length from the @@ -818,6 +823,7 @@ impl From<Vec<NonZero<u8>>> for CString { } } +#[stable(feature = "c_string_from_str", since = "1.85.0")] impl FromStr for CString { type Err = NulError; @@ -830,6 +836,7 @@ impl FromStr for CString { } } +#[stable(feature = "c_string_from_str", since = "1.85.0")] impl TryFrom<CString> for String { type Error = IntoStringError; diff --git a/library/alloc/src/ffi/mod.rs b/library/alloc/src/ffi/mod.rs index 695d7ad07cf..05a2763a225 100644 --- a/library/alloc/src/ffi/mod.rs +++ b/library/alloc/src/ffi/mod.rs @@ -87,5 +87,5 @@ pub use self::c_str::CString; #[stable(feature = "alloc_c_string", since = "1.64.0")] pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError}; -#[unstable(feature = "c_str_module", issue = "112134")] +#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")] pub mod c_str; diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 0664f2c3cf2..24c5d4c92f7 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -603,6 +603,10 @@ impl str { /// Converts a boxed slice of bytes to a boxed string slice without checking /// that the string contains valid UTF-8. /// +/// # Safety +/// +/// * The provided bytes must contain a valid UTF-8 sequence. +/// /// # Examples /// /// ``` |
