11use quickcheck:: { Arbitrary , Gen } ;
22use std:: fmt;
3+ use std:: fmt:: Write as _;
34
45/// `BaseTypeC` is used in generation of C headers to represent the C language's
56/// primitive types as well as `void*`.
@@ -223,11 +224,10 @@ impl Arbitrary for DeclarationListC {
223224/// Enables to string and format for `DeclarationListC` types.
224225impl fmt:: Display for DeclarationListC {
225226 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
226- let mut display = String :: new ( ) ;
227227 for decl in & self . decls {
228- display += & format ! ( "{decl}" ) ;
228+ write ! ( f , "{decl}" ) ? ;
229229 }
230- write ! ( f , "{display}" )
230+ Ok ( ( ) )
231231 }
232232}
233233
@@ -330,7 +330,7 @@ impl Arbitrary for ArrayDimensionC {
330330
331331 for _ in 1 ..dimensions {
332332 // 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 ) ) ;
334334 }
335335 ArrayDimensionC { def }
336336 }
@@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC {
347347/// identifiers unique.
348348impl MakeUnique for BasicTypeDeclarationC {
349349 fn make_unique ( & mut self , stamp : usize ) {
350- self . ident_id += & format ! ( "_{stamp}" ) ;
350+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
351351 }
352352}
353353
@@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC {
384384/// identifiers unique.
385385impl MakeUnique for StructDeclarationC {
386386 fn make_unique ( & mut self , stamp : usize ) {
387- self . ident_id += & format ! ( "_{stamp}" ) ;
387+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
388388 }
389389}
390390
@@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC {
432432/// identifiers unique.
433433impl MakeUnique for UnionDeclarationC {
434434 fn make_unique ( & mut self , stamp : usize ) {
435- self . ident_id += & format ! ( "_{stamp}" ) ;
435+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
436436 }
437437}
438438
@@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC {
480480/// `FunctionPointerDeclarationC` identifiers unique.
481481impl MakeUnique for FunctionPointerDeclarationC {
482482 fn make_unique ( & mut self , stamp : usize ) {
483- self . ident_id += & format ! ( "_{stamp}" ) ;
483+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
484484 }
485485}
486486
@@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC {
517517/// identifiers unique.
518518impl MakeUnique for FunctionPrototypeC {
519519 fn make_unique ( & mut self , stamp : usize ) {
520- self . ident_id += & format ! ( "_{stamp}" ) ;
520+ let _ = write ! ( self . ident_id , "_{stamp}" ) ;
521521 }
522522}
523523
@@ -586,14 +586,13 @@ impl Arbitrary for ParameterListC {
586586/// Enables to string and format for `ParameterListC` types.
587587impl fmt:: Display for ParameterListC {
588588 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
589- let mut display = String :: new ( ) ;
590589 for ( i, p) in self . params . iter ( ) . enumerate ( ) {
591590 match i {
592- 0 => display += & format ! ( "{p}" ) ,
593- _ => display += & format ! ( ",{p}" ) ,
591+ 0 => write ! ( f , "{p}" ) ? ,
592+ _ => write ! ( f , ",{p}" ) ? ,
594593 }
595594 }
596- write ! ( f , "{display}" )
595+ Ok ( ( ) )
597596 }
598597}
599598
@@ -612,11 +611,10 @@ impl Arbitrary for HeaderC {
612611/// Enables to string and format for `HeaderC` types.
613612impl fmt:: Display for HeaderC {
614613 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
615- let mut display = String :: new ( ) ;
616614 for decl in & self . def . decls {
617- display += & format ! ( "{decl}" ) ;
615+ write ! ( f , "{decl}" ) ? ;
618616 }
619- write ! ( f , "{display}" )
617+ Ok ( ( ) )
620618 }
621619}
622620
0 commit comments