@@ -5,8 +5,8 @@ use crate::svd::{
5
5
} ;
6
6
use core:: u64;
7
7
use log:: warn;
8
- use proc_macro2:: { Ident , Punct , Spacing , Span , TokenStream } ;
9
- use quote:: { quote, ToTokens } ;
8
+ use proc_macro2:: { Delimiter , Group , Ident , Span , TokenStream } ;
9
+ use quote:: quote;
10
10
use std:: collections:: HashSet ;
11
11
use std:: fmt:: Write ;
12
12
use std:: { borrow:: Cow , collections:: BTreeMap } ;
@@ -136,11 +136,12 @@ pub fn render(
136
136
137
137
out. extend ( quote ! {
138
138
#[ doc = #description]
139
- pub mod #mod_ty {
140
- #mod_items
141
- }
139
+ pub mod #mod_ty
142
140
} ) ;
143
141
142
+ let mod_group = Group :: new ( Delimiter :: Brace , mod_items) ;
143
+ out. extend ( quote ! { #mod_group } ) ;
144
+
144
145
Ok ( out)
145
146
}
146
147
}
@@ -297,9 +298,6 @@ pub fn render_register_mod(
297
298
let mut zero_to_modify_fields_bitmap = 0 ;
298
299
let mut one_to_modify_fields_bitmap = 0 ;
299
300
300
- let open = Punct :: new ( '{' , Spacing :: Alone ) ;
301
- let close = Punct :: new ( '}' , Spacing :: Alone ) ;
302
-
303
301
let debug_feature = config
304
302
. impl_debug_feature
305
303
. as_ref ( )
@@ -362,24 +360,21 @@ pub fn render_register_mod(
362
360
}
363
361
364
362
if can_read && !r_impl_items. is_empty ( ) {
365
- mod_items. extend ( quote ! {
366
- impl R #open # r_impl_items #close
367
- } ) ;
363
+ mod_items. extend ( quote ! { impl R } ) ;
364
+ let r_impl_group = Group :: new ( Delimiter :: Brace , quote ! { # r_impl_items } ) ;
365
+ mod_items . extend ( quote ! { #r_impl_group } ) ;
368
366
}
369
367
if !r_debug_impl. is_empty ( ) {
370
- mod_items. extend ( quote ! {
371
- #r_debug_impl
372
- } ) ;
368
+ mod_items. extend ( quote ! { #r_debug_impl } ) ;
373
369
}
374
370
375
371
if can_write {
376
372
mod_items. extend ( quote ! {
377
- impl W #open
373
+ impl W
378
374
} ) ;
379
375
380
- mod_items. extend ( w_impl_items) ;
381
-
382
- close. to_tokens ( & mut mod_items) ;
376
+ let w_impl_group = Group :: new ( Delimiter :: Brace , quote ! { #w_impl_items } ) ;
377
+ mod_items. extend ( quote ! { #w_impl_group } ) ;
383
378
}
384
379
385
380
let doc = format ! (
@@ -461,8 +456,6 @@ fn render_register_mod_debug(
461
456
let name = util:: name_of ( register, config. ignore_groups ) ;
462
457
let span = Span :: call_site ( ) ;
463
458
let regspec_ty = regspec ( & name, config, span) ;
464
- let open = Punct :: new ( '{' , Spacing :: Alone ) ;
465
- let close = Punct :: new ( '}' , Spacing :: Alone ) ;
466
459
let mut r_debug_impl = TokenStream :: new ( ) ;
467
460
let debug_feature = config
468
461
. impl_debug_feature
@@ -473,8 +466,14 @@ fn render_register_mod_debug(
473
466
if access. can_read ( ) && register. read_action . is_none ( ) {
474
467
r_debug_impl. extend ( quote ! {
475
468
#debug_feature
476
- impl core:: fmt:: Debug for R #open
477
- fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result #open
469
+ impl core:: fmt:: Debug for R
470
+ } ) ;
471
+ let mut fmt_outer_impl = TokenStream :: new ( ) ;
472
+ fmt_outer_impl. extend ( quote ! {
473
+ fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result
474
+ } ) ;
475
+ let mut fmt_inner_impl = TokenStream :: new ( ) ;
476
+ fmt_inner_impl. extend ( quote ! {
478
477
f. debug_struct( #name)
479
478
} ) ;
480
479
for & f in cur_fields. iter ( ) {
@@ -488,25 +487,27 @@ fn render_register_mod_debug(
488
487
for suffix in de. indexes ( ) {
489
488
let f_name_n = field_accessor ( & f. name . expand_dim ( & suffix) , config, span) ;
490
489
let f_name_n_s = format ! ( "{f_name_n}" ) ;
491
- r_debug_impl . extend ( quote ! {
490
+ fmt_inner_impl . extend ( quote ! {
492
491
. field( #f_name_n_s, & self . #f_name_n( ) )
493
492
} ) ;
494
493
}
495
494
} else {
496
495
let f_name = f. name . remove_dim ( ) ;
497
496
let f_name = field_accessor ( & f_name, config, span) ;
498
497
let f_name_s = format ! ( "{f_name}" ) ;
499
- r_debug_impl . extend ( quote ! {
498
+ fmt_inner_impl . extend ( quote ! {
500
499
. field( #f_name_s, & self . #f_name( ) )
501
500
} ) ;
502
501
}
503
502
}
504
503
}
505
- r_debug_impl . extend ( quote ! {
504
+ fmt_inner_impl . extend ( quote ! {
506
505
. finish( )
507
- #close
508
- #close
509
506
} ) ;
507
+ let fmt_inner_group = Group :: new ( Delimiter :: Brace , fmt_inner_impl) ;
508
+ fmt_outer_impl. extend ( quote ! { #fmt_inner_group } ) ;
509
+ let fmt_outer_group = Group :: new ( Delimiter :: Brace , fmt_outer_impl) ;
510
+ r_debug_impl. extend ( quote ! { #fmt_outer_group } ) ;
510
511
} else if !access. can_read ( ) || register. read_action . is_some ( ) {
511
512
r_debug_impl. extend ( quote ! {
512
513
#debug_feature
0 commit comments