1
1
use quickcheck:: { Arbitrary , Gen } ;
2
2
use std:: fmt;
3
+ use std:: fmt:: Write as _;
3
4
4
5
/// `BaseTypeC` is used in generation of C headers to represent the C language's
5
6
/// primitive types as well as `void*`.
@@ -223,11 +224,10 @@ impl Arbitrary for DeclarationListC {
223
224
/// Enables to string and format for `DeclarationListC` types.
224
225
impl fmt:: Display for DeclarationListC {
225
226
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
226
- let mut display = String :: new ( ) ;
227
227
for decl in & self . decls {
228
- display += & format ! ( "{decl}" ) ;
228
+ write ! ( f , "{decl}" ) ? ;
229
229
}
230
- write ! ( f , "{display}" )
230
+ Ok ( ( ) )
231
231
}
232
232
}
233
233
@@ -330,7 +330,7 @@ impl Arbitrary for ArrayDimensionC {
330
330
331
331
for _ in 1 ..dimensions {
332
332
// 16 is an arbitrary "not too big" number for capping array size.
333
- def += & format ! ( "[{}]" , gen_range( g, lower_bound, 16 ) ) ;
333
+ let _ = write ! ( def , "[{}]" , gen_range( g, lower_bound, 16 ) ) ;
334
334
}
335
335
ArrayDimensionC { def }
336
336
}
@@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC {
347
347
/// identifiers unique.
348
348
impl MakeUnique for BasicTypeDeclarationC {
349
349
fn make_unique ( & mut self , stamp : usize ) {
350
- self . ident_id += & format ! ( "_{stamp}" ) ;
350
+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
351
351
}
352
352
}
353
353
@@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC {
384
384
/// identifiers unique.
385
385
impl MakeUnique for StructDeclarationC {
386
386
fn make_unique ( & mut self , stamp : usize ) {
387
- self . ident_id += & format ! ( "_{stamp}" ) ;
387
+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
388
388
}
389
389
}
390
390
@@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC {
432
432
/// identifiers unique.
433
433
impl MakeUnique for UnionDeclarationC {
434
434
fn make_unique ( & mut self , stamp : usize ) {
435
- self . ident_id += & format ! ( "_{stamp}" ) ;
435
+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
436
436
}
437
437
}
438
438
@@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC {
480
480
/// `FunctionPointerDeclarationC` identifiers unique.
481
481
impl MakeUnique for FunctionPointerDeclarationC {
482
482
fn make_unique ( & mut self , stamp : usize ) {
483
- self . ident_id += & format ! ( "_{stamp}" ) ;
483
+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
484
484
}
485
485
}
486
486
@@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC {
517
517
/// identifiers unique.
518
518
impl MakeUnique for FunctionPrototypeC {
519
519
fn make_unique ( & mut self , stamp : usize ) {
520
- self . ident_id += & format ! ( "_{stamp}" ) ;
520
+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
521
521
}
522
522
}
523
523
@@ -586,14 +586,13 @@ impl Arbitrary for ParameterListC {
586
586
/// Enables to string and format for `ParameterListC` types.
587
587
impl fmt:: Display for ParameterListC {
588
588
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
589
- let mut display = String :: new ( ) ;
590
589
for ( i, p) in self . params . iter ( ) . enumerate ( ) {
591
590
match i {
592
- 0 => display += & format ! ( "{p}" ) ,
593
- _ => display += & format ! ( ",{p}" ) ,
591
+ 0 => write ! ( f , "{p}" ) ? ,
592
+ _ => write ! ( f , ",{p}" ) ? ,
594
593
}
595
594
}
596
- write ! ( f , "{display}" )
595
+ Ok ( ( ) )
597
596
}
598
597
}
599
598
@@ -612,11 +611,10 @@ impl Arbitrary for HeaderC {
612
611
/// Enables to string and format for `HeaderC` types.
613
612
impl fmt:: Display for HeaderC {
614
613
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
615
- let mut display = String :: new ( ) ;
616
614
for decl in & self . def . decls {
617
- display += & format ! ( "{decl}" ) ;
615
+ write ! ( f , "{decl}" ) ? ;
618
616
}
619
- write ! ( f , "{display}" )
617
+ Ok ( ( ) )
620
618
}
621
619
}
622
620
0 commit comments