@@ -135,16 +135,20 @@ pub enum FromBytesWithNulError {
135
135
}
136
136
137
137
#[ 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 {
141
140
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" ) ,
144
145
}
145
146
}
146
147
}
147
148
149
+ #[ stable( feature = "frombyteswithnulerror_impls" , since = "1.17.0" ) ]
150
+ impl Error for FromBytesWithNulError { }
151
+
148
152
/// An error indicating that no nul byte was present.
149
153
///
150
154
/// A slice used to create a [`CStr`] must contain a nul byte somewhere
@@ -181,18 +185,6 @@ impl Default for &CStr {
181
185
}
182
186
}
183
187
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
-
196
188
impl CStr {
197
189
/// Wraps a raw C string with a safe C string wrapper.
198
190
///
0 commit comments