@@ -8,9 +8,7 @@ use syn::*;
88
99/// The non-exhaustive version of `PartialDebug`
1010///
11- /// Requires the `unstable` feature.
1211/// Only available for structs with named fields.
13- #[ cfg( feature = "unstable" ) ]
1412#[ proc_macro_derive( NonExhaustivePartialDebug ) ]
1513pub fn derive_non_exhaustive ( input : TokenStream ) -> TokenStream {
1614 let input = parse_macro_input ! ( input as ItemStruct ) ;
@@ -27,19 +25,7 @@ pub fn derive_non_exhaustive(input: TokenStream) -> TokenStream {
2725 }
2826 } ;
2927
30- let as_debug_all_fields = fields. iter ( ) . map ( |field| {
31- let name = & field. ident ;
32- quote ! {
33- match :: partialdebug:: specialization:: AsDebug :: as_debug( & self . #name) {
34- :: core:: option:: Option :: None => {
35- __exhaustive = false ;
36- }
37- :: core:: option:: Option :: Some ( field) => {
38- __s. field( stringify!( #name) , field) ;
39- }
40- }
41- }
42- } ) ;
28+ let as_debug_all_fields = fields. iter ( ) . map ( gen_field_as_debug_non_exhaustive) ;
4329
4430 let expanded = quote ! {
4531 impl #impl_generics :: core:: fmt:: Debug for #name #ty_generics #where_clause{
@@ -61,6 +47,39 @@ pub fn derive_non_exhaustive(input: TokenStream) -> TokenStream {
6147 TokenStream :: from ( expanded)
6248}
6349
50+ #[ cfg( feature = "unstable" ) ]
51+ fn gen_field_as_debug_non_exhaustive ( field : & Field ) -> TokenStream2 {
52+ let name = & field. ident ;
53+
54+ quote ! {
55+ match :: partialdebug:: specialization:: AsDebug :: as_debug( & self . #name) {
56+ :: core:: option:: Option :: None => {
57+ __exhaustive = false ;
58+ }
59+ :: core:: option:: Option :: Some ( field) => {
60+ __s. field( stringify!( #name) , field) ;
61+ }
62+ }
63+ }
64+ }
65+
66+ #[ cfg( not( feature = "unstable" ) ) ]
67+ fn gen_field_as_debug_non_exhaustive ( field : & Field ) -> TokenStream2 {
68+ let name = & field. ident ;
69+ let field_type = & field. ty ;
70+
71+ quote ! {
72+ match :: partialdebug:: no_specialization:: DebugDetector :: <#field_type>:: as_debug( & self . #name) {
73+ :: core:: option:: Option :: None => {
74+ __exhaustive = false ;
75+ }
76+ :: core:: option:: Option :: Some ( field) => {
77+ __s. field( stringify!( #name) , field) ;
78+ }
79+ }
80+ }
81+ }
82+
6483/// The placeholder version of `PartialDebug`
6584#[ proc_macro_derive( PlaceholderPartialDebug , attributes( debug_placeholder) ) ]
6685pub fn derive_placeholder ( input : TokenStream ) -> TokenStream {
@@ -159,7 +178,7 @@ fn struct_field_conversions<'a>(
159178 }
160179 Some ( name) => ( quote ! { self . #name} , Some ( quote ! { stringify!( #name) , } ) ) ,
161180 } ;
162- gen_field_as_debug ( field, placeholder, field_handle, name_arg)
181+ gen_field_as_debug_placeholder ( field, placeholder, field_handle, name_arg)
163182 } )
164183}
165184
@@ -175,12 +194,12 @@ fn enum_field_conversions<'a>(
175194 }
176195 Some ( name) => ( quote ! { #name} , Some ( quote ! { stringify!( #name) , } ) ) ,
177196 } ;
178- gen_field_as_debug ( field, placeholder, field_handle, name_arg)
197+ gen_field_as_debug_placeholder ( field, placeholder, field_handle, name_arg)
179198 } )
180199}
181200
182201#[ cfg( feature = "unstable" ) ]
183- fn gen_field_as_debug (
202+ fn gen_field_as_debug_placeholder (
184203 field : & Field ,
185204 placeholder : & Option < String > ,
186205 field_handle : TokenStream2 ,
@@ -203,7 +222,7 @@ fn gen_field_as_debug(
203222}
204223
205224#[ cfg( not( feature = "unstable" ) ) ]
206- fn gen_field_as_debug (
225+ fn gen_field_as_debug_placeholder (
207226 field : & Field ,
208227 placeholder : & Option < String > ,
209228 field_handle : TokenStream2 ,
0 commit comments