Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: Move CStr to libcore, and CString to liballoc #94079

Merged
merged 5 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
library: Use type aliases to make CStr(ing) in libcore/liballoc uns…
…table
  • Loading branch information
petrochenkov committed Apr 14, 2022
commit 7f3cc2fbbfbbc257a8763ae817a69452b9a7e31d
8 changes: 4 additions & 4 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use core::str::{self, Utf8Error};
/// and other memory errors.
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub struct CString {
// Invariant 1: the slice ends with a zero byte and has a length of at least one.
// Invariant 2: the slice contains only one zero byte.
Expand All @@ -130,7 +130,7 @@ pub struct CString {
/// let _: NulError = CString::new(b"f\0oo".to_vec()).unwrap_err();
/// ```
#[derive(Clone, PartialEq, Eq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub struct NulError(usize, Vec<u8>);

#[derive(Clone, PartialEq, Eq, Debug)]
Expand All @@ -155,7 +155,7 @@ enum FromBytesWithNulErrorKind {
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err();
/// ```
#[derive(Clone, PartialEq, Eq, Debug)]
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub struct FromVecWithNulError {
error_kind: FromBytesWithNulErrorKind,
bytes: Vec<u8>,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl FromVecWithNulError {
/// This `struct` is created by [`CString::into_string()`]. See
/// its documentation for more.
#[derive(Clone, PartialEq, Eq, Debug)]
#[stable(feature = "cstring_into", since = "1.7.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub struct IntoStringError {
inner: CString,
error: Utf8Error,
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
#[cfg(bootstrap)]
#[unstable(feature = "cstr_internals", issue = "none")]
pub use self::c_str::CStrExt;
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub use self::c_str::FromVecWithNulError;
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "alloc_c_string", issue = "94079")]
pub use self::c_str::{CString, IntoStringError, NulError};

mod c_str;
2 changes: 2 additions & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#![allow(explicit_outlives_requirements)]
//
// Library features:
#![cfg_attr(not(no_global_oom_handling), feature(alloc_c_string))]
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(array_chunks)]
Expand All @@ -105,6 +106,7 @@
#![feature(const_maybe_uninit_write)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_refs_to_cell)]
#![feature(core_c_str)]
#![feature(core_intrinsics)]
#![feature(core_ffi_c)]
#![feature(const_eval_select)]
Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![feature(const_nonnull_slice_from_raw_parts)]
#![feature(const_ptr_write)]
#![feature(const_try)]
#![feature(core_c_str)]
#![feature(core_ffi_c)]
#![feature(core_intrinsics)]
#![feature(drain_filter)]
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use crate::str;
/// [str]: prim@str "str"
#[derive(Hash)]
#[cfg_attr(not(test), rustc_diagnostic_item = "CStr")]
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "core_c_str", issue = "94079")]
#[cfg_attr(not(bootstrap), lang = "CStr")]
// FIXME:
// `fn from` in `impl From<&CStr> for Box<CStr>` current implementation relies
Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct CStr {
/// let _: FromBytesWithNulError = CStr::from_bytes_with_nul(b"f\0oo").unwrap_err();
/// ```
#[derive(Clone, PartialEq, Eq, Debug)]
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
#[unstable(feature = "core_c_str", issue = "94079")]
pub struct FromBytesWithNulError {
kind: FromBytesWithNulErrorKind,
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::marker::PhantomData;
use crate::num::*;
use crate::ops::{Deref, DerefMut};

#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "core_c_str", issue = "94079")]
pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError};

mod c_str;
Expand Down
18 changes: 14 additions & 4 deletions library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,24 @@

#![stable(feature = "rust1", since = "1.0.0")]

/// See [alloc::ffi::FromVecWithNulError].
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
pub use alloc::ffi::FromVecWithNulError;
pub type FromVecWithNulError = alloc::ffi::FromVecWithNulError;
/// See [alloc::ffi::CString].
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc::ffi::{CString, IntoStringError, NulError};
pub type CString = alloc::ffi::CString;
/// See [alloc::ffi::IntoStringError].
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ffi::CStr;
pub type IntoStringError = alloc::ffi::IntoStringError;
/// See [alloc::ffi::NulError].
#[stable(feature = "rust1", since = "1.0.0")]
pub type NulError = alloc::ffi::NulError;
/// See [core::ffi::CStr].
#[stable(feature = "rust1", since = "1.0.0")]
pub type CStr = core::ffi::CStr;
/// See [core::ffi::FromBytesWithNulError].
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub use core::ffi::FromBytesWithNulError;
pub type FromBytesWithNulError = core::ffi::FromBytesWithNulError;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::os_str::{OsStr, OsString};
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
#![feature(atomic_mut_ptr)]
#![feature(char_error_internals)]
#![feature(char_internals)]
#![feature(core_c_str)]
#![feature(core_intrinsics)]
#![feature(cstr_from_bytes_until_nul)]
#![feature(cstr_internals)]
Expand Down Expand Up @@ -288,6 +289,7 @@
//
// Library features (alloc):
#![feature(alloc_layout_extra)]
#![feature(alloc_c_string)]
#![feature(allocator_api)]
#![feature(get_mut_unchecked)]
#![feature(map_try_insert)]
Expand Down