@@ -413,7 +413,7 @@ pub fn fields(
413
413
} ;
414
414
415
415
if let Some ( ( first, dim, increment, suffixes, suffixes_str) ) = & field_dim {
416
- let offset_calc = calculate_offset ( * first, * increment, offset) ;
416
+ let offset_calc = calculate_offset ( * first, * increment, offset, true ) ;
417
417
let value = quote ! { ( ( self . bits >> #offset_calc) & #hexmask) #cast } ;
418
418
let doc = & util:: replace_suffix ( & description, suffixes_str) ;
419
419
r_impl_items. extend ( quote ! {
@@ -793,7 +793,7 @@ pub fn fields(
793
793
}
794
794
795
795
if let Some ( ( first, dim, increment, suffixes, suffixes_str) ) = & field_dim {
796
- let offset_calc = calculate_offset ( * first, * increment, offset) ;
796
+ let offset_calc = calculate_offset ( * first, * increment, offset, false ) ;
797
797
let doc = & util:: replace_suffix ( & description, suffixes_str) ;
798
798
w_impl_items. extend ( quote ! {
799
799
#[ doc = #doc]
@@ -985,7 +985,12 @@ fn add_from_variants(
985
985
} ) ;
986
986
}
987
987
988
- fn calculate_offset ( first : u32 , increment : u32 , offset : u64 ) -> TokenStream {
988
+ fn calculate_offset (
989
+ first : u32 ,
990
+ increment : u32 ,
991
+ offset : u64 ,
992
+ with_parentheses : bool ,
993
+ ) -> TokenStream {
989
994
let mut res = if first != 0 {
990
995
let first = util:: unsuffixed ( first as u64 ) ;
991
996
quote ! { n - #first }
@@ -1002,7 +1007,15 @@ fn calculate_offset(first: u32, increment: u32, offset: u64) -> TokenStream {
1002
1007
}
1003
1008
if offset != 0 {
1004
1009
let offset = & util:: unsuffixed ( offset) ;
1005
- res = quote ! { #res + #offset } ;
1010
+ if with_parentheses {
1011
+ res = quote ! { ( #res + #offset) } ;
1012
+ } else {
1013
+ res = quote ! { #res + #offset } ;
1014
+ }
1015
+ } else {
1016
+ if with_parentheses {
1017
+ res = quote ! { ( #res) } ;
1018
+ }
1006
1019
}
1007
1020
res
1008
1021
}
0 commit comments