Skip to content

Commit 5050913

Browse files
authored
Unrolled build for rust-lang#112136
Rollup merge of rust-lang#112136 - clarfonthey:ffi-c_str, r=cuviper Add std::ffi::c_str module ACP: rust-lang/libs-team#134 `std::ffi` docs before change: ![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17) `std::ffi` docs after change: ![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e) (note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2 parents 3521a2f + 1ea6cd7 commit 5050913

File tree

7 files changed

+79
-16
lines changed

7 files changed

+79
-16
lines changed

library/alloc/src/ffi/c_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! [`CString`] and its related types.
2+
13
#[cfg(test)]
24
mod tests;
35

library/alloc/src/ffi/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@
8080
8181
#![stable(feature = "alloc_ffi", since = "1.64.0")]
8282

83+
#[doc(no_inline)]
8384
#[stable(feature = "alloc_c_string", since = "1.64.0")]
84-
pub use self::c_str::FromVecWithNulError;
85+
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};
86+
87+
#[doc(inline)]
8588
#[stable(feature = "alloc_c_string", since = "1.64.0")]
86-
pub use self::c_str::{CString, IntoStringError, NulError};
89+
pub use self::c_str::CString;
8790

88-
mod c_str;
91+
#[unstable(feature = "c_str_module", issue = "112134")]
92+
pub mod c_str;

library/core/src/ffi/c_str.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! [`CStr`] and its related types.
2+
13
use crate::cmp::Ordering;
24
use crate::error::Error;
35
use crate::ffi::c_char;
@@ -9,15 +11,20 @@ use crate::slice;
911
use crate::slice::memchr;
1012
use crate::str;
1113

14+
// FIXME: because this is doc(inline)d, we *have* to use intra-doc links because the actual link
15+
// depends on where the item is being documented. however, since this is libcore, we can't
16+
// actually reference libstd or liballoc in intra-doc links. so, the best we can do is remove the
17+
// links to `CString` and `String` for now until a solution is developed
18+
1219
/// Representation of a borrowed C string.
1320
///
1421
/// This type represents a borrowed reference to a nul-terminated
1522
/// array of bytes. It can be constructed safely from a <code>&[[u8]]</code>
1623
/// slice, or unsafely from a raw `*const c_char`. It can then be
1724
/// converted to a Rust <code>&[str]</code> by performing UTF-8 validation, or
18-
/// into an owned [`CString`].
25+
/// into an owned `CString`.
1926
///
20-
/// `&CStr` is to [`CString`] as <code>&[str]</code> is to [`String`]: the former
27+
/// `&CStr` is to `CString` as <code>&[str]</code> is to `String`: the former
2128
/// in each pair are borrowed references; the latter are owned
2229
/// strings.
2330
///
@@ -26,9 +33,6 @@ use crate::str;
2633
/// Instead, safe wrappers of FFI functions may leverage the unsafe [`CStr::from_ptr`] constructor
2734
/// to provide a safe interface to other consumers.
2835
///
29-
/// [`CString`]: ../../std/ffi/struct.CString.html
30-
/// [`String`]: ../../std/string/struct.String.html
31-
///
3236
/// # Examples
3337
///
3438
/// Inspecting a foreign C string:
@@ -125,10 +129,13 @@ enum FromBytesWithNulErrorKind {
125129
NotNulTerminated,
126130
}
127131

132+
// FIXME: const stability attributes should not be required here, I think
128133
impl FromBytesWithNulError {
134+
#[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")]
129135
const fn interior_nul(pos: usize) -> FromBytesWithNulError {
130136
FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos) }
131137
}
138+
#[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")]
132139
const fn not_nul_terminated() -> FromBytesWithNulError {
133140
FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated }
134141
}

library/core/src/ffi/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ use crate::fmt;
1313
use crate::marker::PhantomData;
1414
use crate::ops::{Deref, DerefMut};
1515

16+
#[doc(no_inline)]
1617
#[stable(feature = "core_c_str", since = "1.64.0")]
17-
pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError};
18+
pub use self::c_str::FromBytesWithNulError;
1819

19-
mod c_str;
20+
#[doc(no_inline)]
21+
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
22+
pub use self::c_str::FromBytesUntilNulError;
23+
24+
#[doc(inline)]
25+
#[stable(feature = "core_c_str", since = "1.64.0")]
26+
pub use self::c_str::CStr;
27+
28+
#[unstable(feature = "c_str_module", issue = "112134")]
29+
pub mod c_str;
2030

2131
macro_rules! type_alias {
2232
{

library/std/src/ffi/c_str.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! [`CStr`], [`CString`], and related types.
2+
3+
#[stable(feature = "rust1", since = "1.0.0")]
4+
pub use core::ffi::c_str::CStr;
5+
6+
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
7+
pub use core::ffi::c_str::FromBytesWithNulError;
8+
9+
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
10+
pub use core::ffi::c_str::FromBytesUntilNulError;
11+
12+
#[stable(feature = "rust1", since = "1.0.0")]
13+
pub use alloc::ffi::c_str::{CString, NulError};
14+
15+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
16+
pub use alloc::ffi::c_str::FromVecWithNulError;
17+
18+
#[stable(feature = "cstring_into", since = "1.7.0")]
19+
pub use alloc::ffi::c_str::IntoStringError;

library/std/src/ffi/mod.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,32 @@
161161
162162
#![stable(feature = "rust1", since = "1.0.0")]
163163

164-
#[stable(feature = "alloc_c_string", since = "1.64.0")]
165-
pub use alloc::ffi::{CString, FromVecWithNulError, IntoStringError, NulError};
166-
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.73.0")]
167-
pub use core::ffi::FromBytesUntilNulError;
168-
#[stable(feature = "core_c_str", since = "1.64.0")]
169-
pub use core::ffi::{CStr, FromBytesWithNulError};
164+
#[unstable(feature = "c_str_module", issue = "112134")]
165+
pub mod c_str;
166+
167+
#[doc(inline)]
168+
#[stable(feature = "rust1", since = "1.0.0")]
169+
pub use self::c_str::{CStr, CString};
170+
171+
#[doc(no_inline)]
172+
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
173+
pub use self::c_str::FromBytesWithNulError;
174+
175+
#[doc(no_inline)]
176+
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
177+
pub use self::c_str::FromBytesUntilNulError;
178+
179+
#[doc(no_inline)]
180+
#[stable(feature = "rust1", since = "1.0.0")]
181+
pub use self::c_str::NulError;
182+
183+
#[doc(no_inline)]
184+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
185+
pub use self::c_str::FromVecWithNulError;
186+
187+
#[doc(no_inline)]
188+
#[stable(feature = "cstring_into", since = "1.7.0")]
189+
pub use self::c_str::IntoStringError;
170190

171191
#[stable(feature = "rust1", since = "1.0.0")]
172192
#[doc(inline)]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
//
315315
// Library features (core):
316316
// tidy-alphabetical-start
317+
#![feature(c_str_module)]
317318
#![feature(char_internals)]
318319
#![feature(core_intrinsics)]
319320
#![feature(core_io_borrowed_buf)]

0 commit comments

Comments
 (0)