@@ -299,7 +299,6 @@ pub fn fields(
299299 let pc_r = & f. pc_r ;
300300 let mut pc_w = & f. pc_r ;
301301
302- let mut base_pc_w = None ;
303302 let mut evs_r = None ;
304303
305304 let _pc_r = & f. _pc_r ;
@@ -336,21 +335,17 @@ pub fn fields(
336335 }
337336 } ) ;
338337
339- base_pc_w = base . as_ref ( ) . map ( | base| {
338+ if let Some ( base ) = base {
340339 let pc = base. field . to_sanitized_upper_case ( ) ;
341340 let base_pc_r = Ident :: from ( & * format ! ( "{}_A" , pc) ) ;
342- let base_pc_r = derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, description) ;
341+ derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, description) ;
343342
344343 let doc = format ! ( "Reader of field `{}`" , f. name) ;
345344 mod_items. push ( quote ! {
346345 #[ doc = #doc]
347- pub type #_pc_r = crate :: R <#fty, #base_pc_r >;
346+ pub type #_pc_r = crate :: R <#fty, #pc_r >;
348347 } ) ;
349-
350- base_pc_r
351- } ) ;
352-
353- if base. is_none ( ) {
348+ } else {
354349 let has_reserved_variant = evs. values . len ( ) != ( 1 << f. width ) ;
355350 let variants = Variant :: from_enumerated_values ( evs) ?;
356351
@@ -470,13 +465,11 @@ pub fn fields(
470465 if Some ( evs) != evs_r. as_ref ( ) {
471466 pc_w = & f. pc_w ;
472467
473- base_pc_w = base . as_ref ( ) . map ( | base| {
468+ if let Some ( base ) = base {
474469 let pc = base. field . to_sanitized_upper_case ( ) ;
475470 let base_pc_w = Ident :: from ( & * format ! ( "{}_AW" , pc) ) ;
476- derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, description)
477- } ) ;
478-
479- if base. is_none ( ) {
471+ derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, description) ;
472+ } else {
480473 add_from_variants ( mod_items, & variants, pc_w, & f, description, rv) ;
481474 }
482475 }
@@ -496,23 +489,13 @@ pub fn fields(
496489 let sc = & v. sc ;
497490
498491 let doc = util:: escape_brackets ( util:: respace ( & v. doc ) . as_ref ( ) ) ;
499- if let Some ( enum_) = base_pc_w. as_ref ( ) {
500- proxy_items. push ( quote ! {
501- #[ doc = #doc]
502- #[ inline( always) ]
503- pub fn #sc( self ) -> & ' a mut W {
504- self . variant( #enum_:: #pc)
505- }
506- } ) ;
507- } else {
508- proxy_items. push ( quote ! {
509- #[ doc = #doc]
510- #[ inline( always) ]
511- pub fn #sc( self ) -> & ' a mut W {
512- self . variant( #pc_w:: #pc)
513- }
514- } ) ;
515- }
492+ proxy_items. push ( quote ! {
493+ #[ doc = #doc]
494+ #[ inline( always) ]
495+ pub fn #sc( self ) -> & ' a mut W {
496+ self . variant( #pc_w:: #pc)
497+ }
498+ } ) ;
516499 }
517500 }
518501
@@ -681,7 +664,7 @@ fn add_from_variants(mod_items: &mut Vec<Tokens>, variants: &Vec<Variant>, pc: &
681664 } ) ;
682665}
683666
684- fn derive_from_base ( mod_items : & mut Vec < Tokens > , base : & Base , pc : & Ident , base_pc : & Ident , desc : & str ) -> quote :: Tokens {
667+ fn derive_from_base ( mod_items : & mut Vec < Tokens > , base : & Base , pc : & Ident , base_pc : & Ident , desc : & str ) {
685668 if let ( Some ( peripheral) , Some ( register) ) = ( & base. peripheral , & base. register ) {
686669 let pmod_ = peripheral. to_sanitized_snake_case ( ) ;
687670 let rmod_ = register. to_sanitized_snake_case ( ) ;
@@ -693,10 +676,6 @@ fn derive_from_base(mod_items: &mut Vec<Tokens>, base: &Base, pc: &Ident, base_p
693676 pub type #pc =
694677 crate :: #pmod_:: #rmod_:: #base_pc;
695678 } ) ;
696-
697- quote ! {
698- crate :: #pmod_:: #rmod_:: #base_pc
699- }
700679 } else if let Some ( register) = & base. register {
701680 let mod_ = register. to_sanitized_snake_case ( ) ;
702681 let mod_ = Ident :: from ( & * mod_) ;
@@ -706,19 +685,11 @@ fn derive_from_base(mod_items: &mut Vec<Tokens>, base: &Base, pc: &Ident, base_p
706685 pub type #pc =
707686 super :: #mod_:: #base_pc;
708687 } ) ;
709-
710- quote ! {
711- super :: #mod_:: #base_pc
712- }
713688 } else {
714689 mod_items. push ( quote ! {
715690 #[ doc = #desc]
716691 pub type #pc = #base_pc;
717692 } ) ;
718-
719- quote ! {
720- #base_pc
721- }
722693 }
723694}
724695
0 commit comments