@@ -300,7 +300,6 @@ pub fn fields(
300300 let pc_r = & f. pc_r ;
301301 let mut pc_w = & f. pc_r ;
302302
303- let mut base_pc_w = None ;
304303 let mut evs_r = None ;
305304
306305 let _pc_r = & f. _pc_r ;
@@ -337,21 +336,17 @@ pub fn fields(
337336 }
338337 } ) ;
339338
340- base_pc_w = base . as_ref ( ) . map ( | base| {
339+ if let Some ( base ) = base {
341340 let pc = base. field . to_sanitized_upper_case ( ) ;
342- let base_pc_r = Ident :: new ( & format ! ( "{}_A" , pc) , Span :: call_site ( ) ) ;
343- let base_pc_r = derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, description) ;
341+ let base_pc_r = Ident :: new ( & * format ! ( "{}_A" , pc) , Span :: call_site ( ) ) ;
342+ derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, description) ;
344343
345344 let doc = format ! ( "Reader of field `{}`" , f. name) ;
346345 mod_items. push ( quote ! {
347346 #[ doc = #doc]
348- pub type #_pc_r = crate :: R <#fty, #base_pc_r >;
347+ pub type #_pc_r = crate :: R <#fty, #pc_r >;
349348 } ) ;
350-
351- base_pc_r
352- } ) ;
353-
354- if base. is_none ( ) {
349+ } else {
355350 let has_reserved_variant = evs. values . len ( ) != ( 1 << f. width ) ;
356351 let variants = Variant :: from_enumerated_values ( evs) ?;
357352
@@ -471,13 +466,11 @@ pub fn fields(
471466 if Some ( evs) != evs_r. as_ref ( ) {
472467 pc_w = & f. pc_w ;
473468
474- base_pc_w = base . as_ref ( ) . map ( | base| {
469+ if let Some ( base ) = base {
475470 let pc = base. field . to_sanitized_upper_case ( ) ;
476- let base_pc_w = Ident :: new ( & format ! ( "{}_AW" , pc) , Span :: call_site ( ) ) ;
477- derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, description)
478- } ) ;
479-
480- if base. is_none ( ) {
471+ let base_pc_w = Ident :: new ( & * format ! ( "{}_AW" , pc) , Span :: call_site ( ) ) ;
472+ derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, description) ;
473+ } else {
481474 add_from_variants ( mod_items, & variants, pc_w, & f, description, rv) ;
482475 }
483476 }
@@ -497,23 +490,13 @@ pub fn fields(
497490 let sc = & v. sc ;
498491
499492 let doc = util:: escape_brackets ( util:: respace ( & v. doc ) . as_ref ( ) ) ;
500- if let Some ( enum_) = base_pc_w. as_ref ( ) {
501- proxy_items. push ( quote ! {
502- #[ doc = #doc]
503- #[ inline( always) ]
504- pub fn #sc( self ) -> & ' a mut W {
505- self . variant( #enum_:: #pc)
506- }
507- } ) ;
508- } else {
509- proxy_items. push ( quote ! {
510- #[ doc = #doc]
511- #[ inline( always) ]
512- pub fn #sc( self ) -> & ' a mut W {
513- self . variant( #pc_w:: #pc)
514- }
515- } ) ;
516- }
493+ proxy_items. push ( quote ! {
494+ #[ doc = #doc]
495+ #[ inline( always) ]
496+ pub fn #sc( self ) -> & ' a mut W {
497+ self . variant( #pc_w:: #pc)
498+ }
499+ } ) ;
517500 }
518501 }
519502
@@ -677,7 +660,7 @@ fn add_from_variants(mod_items: &mut Vec<TokenStream>, variants: &Vec<Variant>,
677660 } ) ;
678661}
679662
680- fn derive_from_base ( mod_items : & mut Vec < TokenStream > , base : & Base , pc : & Ident , base_pc : & Ident , desc : & str ) -> TokenStream {
663+ fn derive_from_base ( mod_items : & mut Vec < Tokens > , base : & Base , pc : & Ident , base_pc : & Ident , desc : & str ) {
681664 let span = Span :: call_site ( ) ;
682665 if let ( Some ( peripheral) , Some ( register) ) = ( & base. peripheral , & base. register ) {
683666 let pmod_ = peripheral. to_sanitized_snake_case ( ) ;
@@ -690,10 +673,6 @@ fn derive_from_base(mod_items: &mut Vec<TokenStream>, base: &Base, pc: &Ident, b
690673 pub type #pc =
691674 crate :: #pmod_:: #rmod_:: #base_pc;
692675 } ) ;
693-
694- quote ! {
695- crate :: #pmod_:: #rmod_:: #base_pc
696- }
697676 } else if let Some ( register) = & base. register {
698677 let mod_ = register. to_sanitized_snake_case ( ) ;
699678 let mod_ = Ident :: new ( & mod_, span) ;
@@ -703,19 +682,11 @@ fn derive_from_base(mod_items: &mut Vec<TokenStream>, base: &Base, pc: &Ident, b
703682 pub type #pc =
704683 super :: #mod_:: #base_pc;
705684 } ) ;
706-
707- quote ! {
708- super :: #mod_:: #base_pc
709- }
710685 } else {
711686 mod_items. push ( quote ! {
712687 #[ doc = #desc]
713688 pub type #pc = #base_pc;
714689 } ) ;
715-
716- quote ! {
717- #base_pc
718- }
719690 }
720691}
721692
0 commit comments