Skip to content

remove deprecated from core::ffi::c_str #143326

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
26 changes: 9 additions & 17 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,20 @@ pub enum FromBytesWithNulError {
}

#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
impl Error for FromBytesWithNulError {
#[allow(deprecated)]
fn description(&self) -> &str {
impl fmt::Display for FromBytesWithNulError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InteriorNul { .. } => "data provided contains an interior nul byte",
Self::NotNulTerminated => "data provided is not nul terminated",
Self::InteriorNul { position } => {
write!(f, "data provided contains an interior nul byte at byte position {position}")
}
Self::NotNulTerminated => write!(f, "data provided is not nul terminated"),
}
}
}

#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
impl Error for FromBytesWithNulError {}

/// An error indicating that no nul byte was present.
///
/// A slice used to create a [`CStr`] must contain a nul byte somewhere
Expand Down Expand Up @@ -181,18 +185,6 @@ impl Default for &CStr {
}
}

#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
impl fmt::Display for FromBytesWithNulError {
#[allow(deprecated, deprecated_in_future)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.description())?;
if let Self::InteriorNul { position } = self {
write!(f, " at byte pos {position}")?;
}
Ok(())
}
}

impl CStr {
/// Wraps a raw C string with a safe C string wrapper.
///
Expand Down
Loading