@@ -5,13 +5,13 @@ use syn::{DeriveInput, Ident, Path};
55
66const DEFAULT_DERIVES : & [ & str ] = & [ "Debug" , "PartialEq" , "Eq" , "Clone" , "Copy" ] ;
77
8- use crate :: common:: { DeriveVariant , filter_fields, get_meta_list, path_to_string} ;
98#[ cfg( feature = "nested-name" ) ]
109use crate :: common:: { extract_type_ident, macro_rules_field_counter} ;
10+ use crate :: common:: { filter_fields, get_meta_list, path_to_string, DeriveVariant } ;
1111
1212fn get_helper_macro_name ( type_snake : & str ) -> Ident {
1313 Ident :: new (
14- & format ! ( "__{}_field_name_variants" , type_snake ) ,
14+ & format ! ( "__{type_snake }_field_name_variants" ) ,
1515 Span :: call_site ( ) ,
1616 )
1717}
@@ -23,7 +23,7 @@ struct FieldNamePair {
2323
2424/// A single field slot in declaration order
2525enum FieldSlot {
26- /// One or more consecutive regular fields: (variant_ident, field_name)
26+ /// One or more consecutive regular fields: (` variant_ident`, ` field_name` )
2727 Regular ( Vec < FieldNamePair > ) ,
2828 /// A nested field - calls to the inner type's helper macro
2929 #[ cfg( feature = "nested-name" ) ]
@@ -61,7 +61,7 @@ pub struct DeriveFieldName {
6161}
6262
6363impl DeriveFieldName {
64- /// Parses DeriveInput and collects data into [`DeriveFieldName`]
64+ /// Parses ` DeriveInput` and collects data into [`DeriveFieldName`]
6565 pub fn new ( input : DeriveInput ) -> syn:: Result < Self > {
6666 let vis = input. vis ;
6767 let ident = input. ident ;
@@ -105,7 +105,7 @@ impl DeriveFieldName {
105105 continue ;
106106 }
107107 let pair = FieldNamePair {
108- variant_ident : f. variant_ident . to_owned ( ) ,
108+ variant_ident : f. variant_ident . clone ( ) ,
109109 field_name : f. field_ident . to_string ( ) ,
110110 } ;
111111 if let Some ( FieldSlot :: Regular ( pairs) ) = slots. last_mut ( ) {
@@ -129,7 +129,7 @@ impl DeriveFieldName {
129129
130130 /// Generates the derived `FieldName` enum and its implmentations
131131 /// uses either simple or nested expansion path.
132- pub fn expand ( self ) -> syn :: Result < TokenStream2 > {
132+ pub fn expand ( self ) -> TokenStream2 {
133133 #[ cfg( feature = "nested-name" ) ]
134134 {
135135 let has_nested = self
@@ -149,7 +149,7 @@ impl DeriveFieldName {
149149 }
150150
151151 /// Returns the flat list of `FieldNamePair`s
152- /// Only valid when there are no nested slots (expant_simple )
152+ /// Only valid when there are no nested slots (expand simple )
153153 fn get_fields_for_simple ( & self ) -> & [ FieldNamePair ] {
154154 //PERF: this function is called several times instead of once
155155 // debug_assert_eq!(self.slots.len(), 1);
@@ -161,7 +161,7 @@ impl DeriveFieldName {
161161 }
162162
163163 /// Expands with no nested fields
164- fn expand_simple ( & self ) -> syn :: Result < TokenStream2 > {
164+ fn expand_simple ( & self ) -> TokenStream2 {
165165 // No nested fields- exactly one Regular slot.
166166 let pairs = self . get_fields_for_simple ( ) ;
167167 let entries = FieldSlot :: entries ( pairs) ;
@@ -198,19 +198,19 @@ impl DeriveFieldName {
198198 } ;
199199 let variant_counter = quote ! { #variant_count } ;
200200 let enum_def = self . gen_enum_def ( derive_attrs, & variants) ;
201- let field_names_impl = self . gen_field_names_impl ( & constructs, variant_counter) ;
201+ let field_names_impl = self . gen_field_names_impl ( & constructs, & variant_counter) ;
202202
203- Ok ( quote ! {
203+ quote ! {
204204 #enum_def
205205 #field_names_impl
206206 #own_helper
207- } )
207+ }
208208 }
209209
210210 /// Expands the struct with one or more nested fields using a chain of step macros
211211 /// that accumulate `Variant => "name"` pairs
212212 #[ cfg( feature = "nested-name" ) ]
213- fn expand_nested ( & self ) -> syn :: Result < TokenStream2 > {
213+ fn expand_nested ( & self ) -> TokenStream2 {
214214 let type_snake = & self . type_snake ;
215215
216216 let builder_macro_name = Ident :: new (
@@ -275,12 +275,12 @@ impl DeriveFieldName {
275275 }
276276 } ;
277277
278- Ok ( quote ! {
278+ quote ! {
279279 #builder_macro
280280 #( #step_macros) *
281281 #own_helper
282282 #invocation
283- } )
283+ }
284284 }
285285
286286 /// Emit the builder macro that, once it has the full flat list of
@@ -294,7 +294,7 @@ impl DeriveFieldName {
294294 let variant_counter = macro_rules_field_counter ( ) ;
295295 let enum_def = self . gen_enum_def ( enum_derives, & [ quote ! ( $( $variant) , * ) ] ) ;
296296 let field_names_impl =
297- self . gen_field_names_impl ( & [ quote ! ( $( #enum_ty:: $variant) , * ) ] , variant_counter) ;
297+ self . gen_field_names_impl ( & [ quote ! ( $( #enum_ty:: $variant) , * ) ] , & variant_counter) ;
298298
299299 quote ! {
300300 #[ doc( hidden) ]
@@ -322,11 +322,11 @@ impl DeriveFieldName {
322322 }
323323
324324 /// Generates the `impl FieldNames<N> for OriginalStruct` block
325- /// variant_counter has to be `Tokenstream2` because nested enum field names aren't known at derive macro level
325+ /// ` variant_counter` has to be `Tokenstream2` because nested enum field names aren't known at derive macro level
326326 fn gen_field_names_impl (
327327 & self ,
328328 constructs : & [ TokenStream2 ] ,
329- variant_counter : TokenStream2 ,
329+ variant_counter : & TokenStream2 ,
330330 ) -> TokenStream2 {
331331 let ( impl_generics, ty_generics, where_clause) = self . generics . split_for_impl ( ) ;
332332 let ident = & self . ident ;
0 commit comments