@@ -191,29 +191,8 @@ pub trait Write {
191
191
/// assert_eq!(&buf, "world");
192
192
/// ```
193
193
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
194
- fn write_fmt ( & mut self , args : Arguments ) -> Result {
195
- // This Adapter is needed to allow `self` (of type `&mut
196
- // Self`) to be cast to a Write (below) without
197
- // requiring a `Sized` bound.
198
- struct Adapter < ' a , T : ?Sized +' a > ( & ' a mut T ) ;
199
-
200
- impl < T : ?Sized > Write for Adapter < ' _ , T >
201
- where T : Write
202
- {
203
- fn write_str ( & mut self , s : & str ) -> Result {
204
- self . 0 . write_str ( s)
205
- }
206
-
207
- fn write_char ( & mut self , c : char ) -> Result {
208
- self . 0 . write_char ( c)
209
- }
210
-
211
- fn write_fmt ( & mut self , args : Arguments ) -> Result {
212
- self . 0 . write_fmt ( args)
213
- }
214
- }
215
-
216
- write ( & mut Adapter ( self ) , args)
194
+ fn write_fmt ( mut self : & mut Self , args : Arguments ) -> Result {
195
+ write ( & mut self , args)
217
196
}
218
197
}
219
198
@@ -268,7 +247,7 @@ struct Void {
268
247
/// family of functions. It contains a function to format the given value. At
269
248
/// compile time it is ensured that the function and the value have the correct
270
249
/// types, and then this struct is used to canonicalize arguments to one type.
271
- #[ derive( Copy ) ]
250
+ #[ derive( Copy , Clone ) ]
272
251
#[ allow( missing_debug_implementations) ]
273
252
#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" ,
274
253
issue = "0" ) ]
@@ -278,14 +257,6 @@ pub struct ArgumentV1<'a> {
278
257
formatter : fn ( & Void , & mut Formatter ) -> Result ,
279
258
}
280
259
281
- #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" ,
282
- issue = "0" ) ]
283
- impl Clone for ArgumentV1 < ' _ > {
284
- fn clone ( & self ) -> Self {
285
- * self
286
- }
287
- }
288
-
289
260
impl < ' a > ArgumentV1 < ' a > {
290
261
#[ inline( never) ]
291
262
fn show_usize ( x : & usize , f : & mut Formatter ) -> Result {
@@ -1105,7 +1076,7 @@ impl<'a> Formatter<'a> {
1105
1076
self . args [ i] . as_usize ( )
1106
1077
}
1107
1078
rt:: v1:: Count :: NextParam => {
1108
- self . curarg . next ( ) . and_then ( |arg| arg . as_usize ( ) )
1079
+ self . curarg . next ( ) ? . as_usize ( )
1109
1080
}
1110
1081
}
1111
1082
}
@@ -1171,15 +1142,15 @@ impl<'a> Formatter<'a> {
1171
1142
sign = Some ( '+' ) ; width += 1 ;
1172
1143
}
1173
1144
1174
- let mut prefixed = false ;
1175
- if self . alternate ( ) {
1176
- prefixed = true ; width += prefix. chars ( ) . count ( ) ;
1145
+ let prefixed = self . alternate ( ) ;
1146
+ if prefixed {
1147
+ width += prefix. chars ( ) . count ( ) ;
1177
1148
}
1178
1149
1179
1150
// Writes the sign if it exists, and then the prefix if it was requested
1180
1151
let write_prefix = |f : & mut Formatter | {
1181
1152
if let Some ( c) = sign {
1182
- f. buf . write_str ( c . encode_utf8 ( & mut [ 0 ; 4 ] ) ) ?;
1153
+ f. buf . write_char ( c ) ?;
1183
1154
}
1184
1155
if prefixed { f. buf . write_str ( prefix) }
1185
1156
else { Ok ( ( ) ) }
@@ -1341,7 +1312,7 @@ impl<'a> Formatter<'a> {
1341
1312
1342
1313
// remove the sign from the formatted parts
1343
1314
formatted. sign = b"" ;
1344
- width = if width < sign . len ( ) { 0 } else { width - sign. len ( ) } ;
1315
+ width = width. saturating_sub ( sign. len ( ) ) ;
1345
1316
align = rt:: v1:: Alignment :: Right ;
1346
1317
self . fill = '0' ;
1347
1318
self . align = rt:: v1:: Alignment :: Right ;
0 commit comments