@@ -135,16 +135,20 @@ pub enum FromBytesWithNulError {
135135}
136136
137137#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
138- impl Error for FromBytesWithNulError {
139- #[allow(deprecated)]
140- fn description(&self) -> &str {
138+ impl fmt::Display for FromBytesWithNulError {
139+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141140 match self {
142- Self::InteriorNul { .. } => "data provided contains an interior nul byte",
143- Self::NotNulTerminated => "data provided is not nul terminated",
141+ Self::InteriorNul { position } => {
142+ write!(f, "data provided contains an interior nul byte at byte position {position}")
143+ }
144+ Self::NotNulTerminated => write!(f, "data provided is not nul terminated"),
144145 }
145146 }
146147}
147148
149+ #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
150+ impl Error for FromBytesWithNulError {}
151+
148152/// An error indicating that no nul byte was present.
149153///
150154/// A slice used to create a [`CStr`] must contain a nul byte somewhere
@@ -181,18 +185,6 @@ impl Default for &CStr {
181185 }
182186}
183187
184- #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
185- impl fmt::Display for FromBytesWithNulError {
186- #[allow(deprecated, deprecated_in_future)]
187- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
188- f.write_str(self.description())?;
189- if let Self::InteriorNul { position } = self {
190- write!(f, " at byte pos {position}")?;
191- }
192- Ok(())
193- }
194- }
195-
196188impl CStr {
197189 /// Wraps a raw C string with a safe C string wrapper.
198190 ///
0 commit comments