@@ -282,17 +282,17 @@ pub fn fields(
282282 }
283283 } ;
284284
285+ r_impl_items. extend ( quote ! {
286+ #[ doc = #description_with_bits]
287+ #[ inline( always) ]
288+ pub fn #sc( & self ) -> #_pc_r {
289+ #_pc_r:: new ( #value )
290+ }
291+ } ) ;
292+
285293 if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Read ) {
286294 evs_r = Some ( evs. clone ( ) ) ;
287295
288- r_impl_items. extend ( quote ! {
289- #[ doc = #description_with_bits]
290- #[ inline( always) ]
291- pub fn #sc( & self ) -> #_pc_r {
292- #_pc_r:: new( #value )
293- }
294- } ) ;
295-
296296 if let Some ( base) = base {
297297 let pc = base. field . to_sanitized_upper_case ( ) ;
298298 let base_pc_r = Ident :: new ( & ( pc. clone ( ) + "_A" ) , span) ;
@@ -309,50 +309,50 @@ pub fn fields(
309309
310310 add_from_variants ( mod_items, & variants, & pc_r, & fty, & description, rv) ;
311311
312- let mut enum_items = vec ! [ ] ;
312+ let mut enum_items = TokenStream :: new ( ) ;
313313
314- let mut arms = variants
315- . iter ( )
316- . map ( |v| {
317- let i = util:: unsuffixed_or_bool ( v. value , width) ;
318- let pc = & v. pc ;
314+ let mut arms = TokenStream :: new ( ) ;
315+ for v in variants. iter ( ) . map ( |v| {
316+ let i = util:: unsuffixed_or_bool ( v. value , width) ;
317+ let pc = & v. pc ;
319318
320- if has_reserved_variant {
321- quote ! { #i => Val ( #pc_r:: #pc) }
322- } else {
323- quote ! { #i => #pc_r:: #pc }
324- }
325- } )
326- . collect :: < Vec < _ > > ( ) ;
319+ if has_reserved_variant {
320+ quote ! { #i => Val ( #pc_r:: #pc) , }
321+ } else {
322+ quote ! { #i => #pc_r:: #pc, }
323+ }
324+ } ) {
325+ arms. extend ( v) ;
326+ }
327327
328328 if has_reserved_variant {
329- arms. push ( quote ! {
330- i => Res ( i)
329+ arms. extend ( quote ! {
330+ i => Res ( i) ,
331331 } ) ;
332332 } else if 1 << width. to_ty_width ( ) ? != variants. len ( ) {
333- arms. push ( quote ! {
334- _ => unreachable!( )
333+ arms. extend ( quote ! {
334+ _ => unreachable!( ) ,
335335 } ) ;
336336 }
337337
338338 if has_reserved_variant {
339- enum_items. push ( quote ! {
339+ enum_items. extend ( quote ! {
340340 ///Get enumerated values variant
341341 #[ inline( always) ]
342342 pub fn variant( & self ) -> crate :: Variant <#fty, #pc_r> {
343343 use crate :: Variant :: * ;
344344 match self . bits {
345- #( # arms) , *
345+ #arms
346346 }
347347 }
348348 } ) ;
349349 } else {
350- enum_items. push ( quote ! {
350+ enum_items. extend ( quote ! {
351351 ///Get enumerated values variant
352352 #[ inline( always) ]
353353 pub fn variant( & self ) -> #pc_r {
354354 match self . bits {
355- #( # arms) , *
355+ #arms
356356 }
357357 }
358358 } ) ;
@@ -372,7 +372,7 @@ pub fn fields(
372372 ) ;
373373
374374 let doc = format ! ( "Checks if the value of the field is `{}`" , pc) ;
375- enum_items. push ( quote ! {
375+ enum_items. extend ( quote ! {
376376 #[ doc = #doc]
377377 #[ inline( always) ]
378378 pub fn #is_variant( & self ) -> bool {
@@ -386,19 +386,11 @@ pub fn fields(
386386 #[ doc = #doc]
387387 pub type #_pc_r = crate :: R <#fty, #pc_r>;
388388 impl #_pc_r {
389- #( # enum_items) *
389+ #enum_items
390390 }
391391 } ) ;
392392 }
393393 } else {
394- r_impl_items. extend ( quote ! {
395- #[ doc = #description_with_bits]
396- #[ inline( always) ]
397- pub fn #sc( & self ) -> #_pc_r {
398- #_pc_r:: new ( #value )
399- }
400- } ) ;
401-
402394 let doc = format ! ( "Reader of field `{}`" , f. name) ;
403395 mod_items. extend ( quote ! {
404396 #[ doc = #doc]
@@ -411,7 +403,7 @@ pub fn fields(
411403 let new_pc_w = Ident :: new ( & ( pc. clone ( ) + "_AW" ) , span) ;
412404 let _pc_w = Ident :: new ( & ( pc. clone ( ) + "_W" ) , span) ;
413405
414- let mut proxy_items = vec ! [ ] ;
406+ let mut proxy_items = TokenStream :: new ( ) ;
415407 let mut unsafety = unsafety ( f. write_constraint . as_ref ( ) , width) ;
416408
417409 if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Write ) {
@@ -432,7 +424,7 @@ pub fn fields(
432424 }
433425 }
434426
435- proxy_items. push ( quote ! {
427+ proxy_items. extend ( quote ! {
436428 ///Writes `variant` to the field
437429 #[ inline( always) ]
438430 pub fn variant( self , variant: #pc_w) -> & ' a mut W {
@@ -447,7 +439,7 @@ pub fn fields(
447439 let sc = & v. sc ;
448440
449441 let doc = util:: escape_brackets ( util:: respace ( & v. doc ) . as_ref ( ) ) ;
450- proxy_items. push ( quote ! {
442+ proxy_items. extend ( quote ! {
451443 #[ doc = #doc]
452444 #[ inline( always) ]
453445 pub fn #sc( self ) -> & ' a mut W {
@@ -458,7 +450,7 @@ pub fn fields(
458450 }
459451
460452 if width == 1 {
461- proxy_items. push ( quote ! {
453+ proxy_items. extend ( quote ! {
462454 ///Sets the field bit
463455 #[ inline( always) ]
464456 pub #unsafety fn set_bit( self ) -> & ' a mut W {
@@ -473,7 +465,7 @@ pub fn fields(
473465 } ) ;
474466 }
475467
476- proxy_items. push ( if offset != 0 {
468+ proxy_items. extend ( if offset != 0 {
477469 let offset = & util:: unsuffixed ( offset) ;
478470 quote ! {
479471 ///Writes raw bits to the field
@@ -502,7 +494,7 @@ pub fn fields(
502494 }
503495
504496 impl <' a> #_pc_w<' a> {
505- #( # proxy_items) *
497+ #proxy_items
506498 }
507499 } ) ;
508500
@@ -587,18 +579,18 @@ fn add_from_variants(
587579 ( quote ! { #[ repr( #fty) ] } , quote ! { variant as _ } )
588580 } ;
589581
590- let vars = variants
591- . iter ( )
592- . map ( |v| {
593- let desc = util :: escape_brackets ( & format ! ( "{}: {}" , v . value , v . doc ) ) ;
594- let pcv = & v . pc ;
595- let pcval = & util :: unsuffixed ( v . value ) ;
596- quote ! {
597- # [ doc = #desc ]
598- #pcv = #pcval
599- }
600- } )
601- . collect :: < Vec < _ > > ( ) ;
582+ let mut vars = TokenStream :: new ( ) ;
583+ for v in variants . iter ( ) . map ( |v| {
584+ let desc = util :: escape_brackets ( & format ! ( "{}: {}" , v . value , v . doc ) ) ;
585+ let pcv = & v . pc ;
586+ let pcval = & util :: unsuffixed ( v . value ) ;
587+ quote ! {
588+ # [ doc = #desc ]
589+ #pcv = #pcval ,
590+ }
591+ } ) {
592+ vars . extend ( v ) ;
593+ }
602594
603595 let desc = if let Some ( rv) = reset_value {
604596 format ! ( "{}\n \n Value on reset: {}" , desc, rv)
@@ -611,7 +603,7 @@ fn add_from_variants(
611603 #[ derive( Clone , Copy , Debug , PartialEq ) ]
612604 #repr
613605 pub enum #pc {
614- #( # vars) , *
606+ #vars
615607 }
616608 impl From <#pc> for #fty {
617609 #[ inline( always) ]
0 commit comments