1111//!
1212//! ## Requirements
1313//!
14- //! - Must also derive or implement [ `facet::Facet`]
14+ //! - Must also derive or implement `facet::Facet`
1515//! - Sensitive fields marked with `#[facet(sensitive)]`
1616//!
1717//! ## Performance
5454use facet_macros_parse:: * ;
5555use quote:: quote;
5656
57+ /// Type alias for Results with boxed errors to avoid large error variants
58+ type BoxedResult < T > = std:: result:: Result < T , Box < facet_macros_parse:: Error > > ;
59+
5760/// Derives `std::fmt::Debug` with automatic redaction for sensitive fields.
5861///
5962/// # Supported Types
@@ -161,11 +164,11 @@ pub fn derive_safe_debug(input: proc_macro::TokenStream) -> proc_macro::TokenStr
161164 }
162165}
163166
164- fn derive_facet_debug_impl ( input : & TokenStream ) -> Result < TokenStream > {
167+ fn derive_facet_debug_impl ( input : & TokenStream ) -> BoxedResult < TokenStream > {
165168 let mut iter = input. to_token_iter ( ) ;
166169
167170 // Parse the input as an ADT (struct or enum)
168- let adt: AdtDecl = iter. parse ( ) ?;
171+ let adt: AdtDecl = iter. parse ( ) . map_err ( Box :: new ) ?;
169172
170173 match adt {
171174 AdtDecl :: Struct ( s) => derive_for_struct ( s) ,
@@ -244,7 +247,7 @@ macro_rules! extract_type_param_bounds {
244247///
245248/// This takes a fail-safe approach: if reflection fails, ALL fields are
246249/// redacted to prevent accidental data leakage.
247- fn derive_for_struct ( parsed : Struct ) -> Result < TokenStream > {
250+ fn derive_for_struct ( parsed : Struct ) -> BoxedResult < TokenStream > {
248251 let struct_name = & parsed. name ;
249252
250253 // Extract generics - convert to TokenStream
@@ -297,7 +300,6 @@ fn derive_for_struct(parsed: Struct) -> Result<TokenStream> {
297300 // Generate field checks (when metadata is available)
298301 let field_checks: Vec < _ > = fields
299302 . content
300- . 0
301303 . iter ( )
302304 . enumerate ( )
303305 . map ( |( idx, field) | {
@@ -317,7 +319,6 @@ fn derive_for_struct(parsed: Struct) -> Result<TokenStream> {
317319 // Generate fallback (when metadata is unavailable) - redact for safety
318320 let fallback_fields: Vec < _ > = fields
319321 . content
320- . 0
321322 . iter ( )
322323 . map ( |field| {
323324 let field_name = & field. value . name ;
@@ -352,7 +353,6 @@ fn derive_for_struct(parsed: Struct) -> Result<TokenStream> {
352353 // Generate field checks (when metadata is available)
353354 let field_checks: Vec < _ > = fields
354355 . content
355- . 0
356356 . iter ( )
357357 . enumerate ( )
358358 . map ( |( idx, _field) | {
@@ -370,7 +370,7 @@ fn derive_for_struct(parsed: Struct) -> Result<TokenStream> {
370370 . collect ( ) ;
371371
372372 // Generate fallback (when metadata is unavailable) - redact for safety
373- let fallback_fields: Vec < _ > = ( 0 ..fields. content . 0 . len ( ) )
373+ let fallback_fields: Vec < _ > = ( 0 ..fields. content . len ( ) )
374374 . map ( |_| {
375375 quote ! {
376376 debug_tuple. field( & "[REDACTED:NO_METADATA]" ) ;
@@ -428,7 +428,7 @@ fn derive_for_struct(parsed: Struct) -> Result<TokenStream> {
428428/// The generated code takes a fail-conservative approach: if reflection
429429/// fails, ONLY the enum type name is written with no variant or field data,
430430/// preventing any potential data leakage.
431- fn derive_for_enum ( parsed : Enum ) -> Result < TokenStream > {
431+ fn derive_for_enum ( parsed : Enum ) -> BoxedResult < TokenStream > {
432432 let enum_name = & parsed. name ;
433433
434434 // Extract generics - same as structs
@@ -467,7 +467,6 @@ fn derive_for_enum(parsed: Enum) -> Result<TokenStream> {
467467 let match_arms: Vec < _ > = parsed
468468 . body
469469 . content
470- . 0
471470 . iter ( )
472471 . enumerate ( )
473472 . map ( |( variant_idx, variant_like) | {
@@ -485,7 +484,7 @@ fn derive_for_enum(parsed: Enum) -> Result<TokenStream> {
485484 }
486485 EnumVariantData :: Tuple ( tuple_variant) => {
487486 let variant_name = & tuple_variant. name ;
488- let field_count = tuple_variant. fields . content . 0 . len ( ) ;
487+ let field_count = tuple_variant. fields . content . len ( ) ;
489488
490489 // Generate field bindings: _field_0, _field_1, _field_2, ...
491490 let bindings: Vec < _ > = ( 0 ..field_count) . map ( |i| quote:: format_ident!( "_field_{}" , i) ) . collect ( ) ;
@@ -517,7 +516,7 @@ fn derive_for_enum(parsed: Enum) -> Result<TokenStream> {
517516 }
518517 EnumVariantData :: Struct ( struct_variant) => {
519518 let variant_name = & struct_variant. name ;
520- let fields = & struct_variant. fields . content . 0 ;
519+ let fields = & struct_variant. fields . content ;
521520
522521 // Generate field bindings: ref field1, ref field2, ...
523522 let field_names: Vec < _ > = fields. iter ( ) . map ( |field| & field. value . name ) . collect ( ) ;
0 commit comments