@@ -607,19 +607,27 @@ fn generate_checked_bit_pattern_struct(
607
607
let field_name = & field_names[ ..] ;
608
608
let field_ty = & field_tys[ ..] ;
609
609
610
- let derive_dbg =
611
- quote ! ( #[ cfg_attr( not( target_arch = "spirv" ) , derive( Debug ) ) ] ) ;
612
-
613
610
Ok ( (
614
611
quote ! {
615
612
#[ doc = #GENERATED_TYPE_DOCUMENTATION ]
616
613
#repr
617
614
#[ derive( Clone , Copy , #crate_name:: AnyBitPattern ) ]
618
- #derive_dbg
619
615
#[ allow( missing_docs) ]
620
616
pub struct #bits_ty {
621
617
#( #field_name: <#field_ty as #crate_name:: CheckedBitPattern >:: Bits , ) *
622
618
}
619
+
620
+ #[ allow( unexpected_cfgs) ]
621
+ const _: ( ) = {
622
+ #[ cfg( not( target_arch = "spirv" ) ) ]
623
+ impl :: core:: fmt:: Debug for #bits_ty {
624
+ fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
625
+ let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #bits_ty) ) ;
626
+ #( :: core:: fmt:: DebugStruct :: field( & mut debug_struct, :: core:: stringify!( #field_name) , & self . #field_name) ; ) *
627
+ :: core:: fmt:: DebugStruct :: finish( & mut debug_struct)
628
+ }
629
+ }
630
+ } ;
623
631
} ,
624
632
quote ! {
625
633
type Bits = #bits_ty;
@@ -711,9 +719,6 @@ fn generate_checked_bit_pattern_enum_with_fields(
711
719
let representation = get_repr ( & input. attrs ) ?;
712
720
let vis = & input. vis ;
713
721
714
- let derive_dbg =
715
- quote ! ( #[ cfg_attr( not( target_arch = "spirv" ) , derive( Debug ) ) ] ) ;
716
-
717
722
match representation. repr {
718
723
Repr :: Rust => unreachable ! ( ) ,
719
724
repr @ ( Repr :: C | Repr :: CWithDiscriminant ( _) ) => {
@@ -793,27 +798,42 @@ fn generate_checked_bit_pattern_enum_with_fields(
793
798
quote ! {
794
799
#[ doc = #GENERATED_TYPE_DOCUMENTATION ]
795
800
#[ derive( :: core:: clone:: Clone , :: core:: marker:: Copy , #crate_name:: AnyBitPattern ) ]
796
- #derive_dbg
797
801
#bits_repr
798
802
#vis struct #bits_ty_ident {
799
803
tag: #integer,
800
804
payload: #variants_union_ident,
801
805
}
802
806
807
+ #[ allow( unexpected_cfgs) ]
808
+ const _: ( ) = {
809
+ #[ cfg( not( target_arch = "spirv" ) ) ]
810
+ impl :: core:: fmt:: Debug for #bits_ty_ident {
811
+ fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
812
+ let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #bits_ty_ident) ) ;
813
+ :: core:: fmt:: DebugStruct :: field( & mut debug_struct, "tag" , & self . tag) ;
814
+ :: core:: fmt:: DebugStruct :: field( & mut debug_struct, "payload" , & self . payload) ;
815
+ :: core:: fmt:: DebugStruct :: finish( & mut debug_struct)
816
+ }
817
+ }
818
+ } ;
819
+
803
820
#[ derive( :: core:: clone:: Clone , :: core:: marker:: Copy , #crate_name:: AnyBitPattern ) ]
804
821
#[ repr( C ) ]
805
822
#[ allow( non_snake_case) ]
806
823
#vis union #variants_union_ident {
807
824
#( #union_fields, ) *
808
825
}
809
826
810
- #[ cfg( not( target_arch = "spirv" ) ) ]
811
- impl :: core:: fmt:: Debug for #variants_union_ident {
812
- fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
813
- let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #variants_union_ident) ) ;
814
- :: core:: fmt:: DebugStruct :: finish_non_exhaustive( & mut debug_struct)
827
+ #[ allow( unexpected_cfgs) ]
828
+ const _: ( ) = {
829
+ #[ cfg( not( target_arch = "spirv" ) ) ]
830
+ impl :: core:: fmt:: Debug for #variants_union_ident {
831
+ fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
832
+ let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #variants_union_ident) ) ;
833
+ :: core:: fmt:: DebugStruct :: finish_non_exhaustive( & mut debug_struct)
834
+ }
815
835
}
816
- }
836
+ } ;
817
837
818
838
#( #variant_struct_definitions) *
819
839
} ,
@@ -930,14 +950,17 @@ fn generate_checked_bit_pattern_enum_with_fields(
930
950
#( #union_fields, ) *
931
951
}
932
952
933
- #[ cfg( not( target_arch = "spirv" ) ) ]
934
- impl :: core:: fmt:: Debug for #bits_ty_ident {
935
- fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
936
- let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #bits_ty_ident) ) ;
937
- :: core:: fmt:: DebugStruct :: field( & mut debug_struct, "tag" , unsafe { & self . __tag } ) ;
938
- :: core:: fmt:: DebugStruct :: finish_non_exhaustive( & mut debug_struct)
953
+ #[ allow( unexpected_cfgs) ]
954
+ const _: ( ) = {
955
+ #[ cfg( not( target_arch = "spirv" ) ) ]
956
+ impl :: core:: fmt:: Debug for #bits_ty_ident {
957
+ fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
958
+ let mut debug_struct = :: core:: fmt:: Formatter :: debug_struct( f, :: core:: stringify!( #bits_ty_ident) ) ;
959
+ :: core:: fmt:: DebugStruct :: field( & mut debug_struct, "tag" , unsafe { & self . __tag } ) ;
960
+ :: core:: fmt:: DebugStruct :: finish_non_exhaustive( & mut debug_struct)
961
+ }
939
962
}
940
- }
963
+ } ;
941
964
942
965
#( #variant_struct_definitions) *
943
966
} ,
0 commit comments