From 5bb154c737afda3a127b0eb3903b246f3a0ed7e3 Mon Sep 17 00:00:00 2001 From: SupperZum Date: Wed, 23 Apr 2025 09:28:31 +0300 Subject: [PATCH 1/2] fix clippy --- module/core/former_meta/src/derive_former.rs | 2 +- .../src/derive_former/former_enum.rs | 311 +++++++++--------- .../src/derive_former/former_struct.rs | 6 +- module/core/former_types/src/forming.rs | 4 +- module/core/macro_tools/src/ident.rs | 1 + module/core/macro_tools/src/item.rs | 2 +- module/core/macro_tools/src/phantom.rs | 2 +- module/core/macro_tools/src/typ.rs | 4 +- module/core/mod_interface_meta/src/impls.rs | 2 +- .../core/mod_interface_meta/src/use_tree.rs | 4 +- module/core/pth/src/path.rs | 2 +- module/move/wca/src/ca/help.rs | 2 +- module/move/wca/src/ca/tool/table.rs | 3 +- module/move/willbe/src/action/crate_doc.rs | 26 +- module/move/willbe/src/action/deploy_renew.rs | 2 +- .../src/action/readme_health_table_renew.rs | 17 +- module/move/willbe/src/command/crate_doc.rs | 7 +- .../src/command/readme_headers_renew.rs | 2 +- module/move/willbe/src/entity/diff.rs | 10 +- module/move/willbe/src/entity/version.rs | 4 +- module/move/willbe/src/entity/workspace.rs | 4 +- module/move/willbe/tests/inc/entity/diff.rs | 4 +- 22 files changed, 216 insertions(+), 205 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 505af919c3..1299b73748 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -93,7 +93,7 @@ r"derive : Former item : {item}", ); diag::report_print( about, original_input, debug ); - }; + } Ok( former_mutator_code ) } diff --git a/module/core/former_meta/src/derive_former/former_enum.rs b/module/core/former_meta/src/derive_former/former_enum.rs index 164c1d44b4..09615049c5 100644 --- a/module/core/former_meta/src/derive_former/former_enum.rs +++ b/module/core/former_meta/src/derive_former/former_enum.rs @@ -160,7 +160,7 @@ pub(super) fn former_for_enum let field_attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; // Determine if the inner type likely has its own Former (heuristic) - let inner_former_exists = if let syn::Type::Path( tp ) = inner_type { tp.path.segments.last().map_or( false, | seg | !matches!( seg.ident.to_string().as_str(), "bool" | "char" | "str" | "String" | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" | "u8" | "u16" | "u32" | "u64" | "u128" | "usize" | "f32" | "f64" ) ) } else { false }; + let inner_former_exists = if let syn::Type::Path( tp ) = inner_type { tp.path.segments.last().is_some_and( | seg | !matches!( seg.ident.to_string().as_str(), "bool" | "char" | "str" | "String" | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" | "u8" | "u16" | "u32" | "u64" | "u128" | "usize" | "f32" | "f64" ) ) } else { false }; if wants_scalar || ( !wants_subform_scalar && !inner_former_exists ) { @@ -179,7 +179,7 @@ pub(super) fn former_for_enum enum_name, variant_ident, &variant.fields, // Pass fields here - &generics, + generics, &implicit_former_name, &implicit_storage_name, &implicit_def_name, @@ -276,7 +276,7 @@ pub(super) fn former_for_enum let inner_storage_name = format_ident!( "{}FormerStorage", inner_type_name ); let inner_def_name = format_ident!( "{}FormerDefinition", inner_type_name ); let inner_def_types_name = format_ident!( "{}FormerDefinitionTypes", inner_type_name ); - let inner_generics_ty : syn::punctuated::Punctuated<_,_> = match &inner_generics { syn::PathArguments::AngleBracketed( args ) => args.args.clone(), _ => Default::default() }; + let inner_generics_ty : syn::punctuated::Punctuated<_,_> = match &inner_generics { syn::PathArguments::AngleBracketed( args ) => args.args.clone(), _ => syn::punctuated::Punctuated::default() }; let inner_generics_ty_comma = if inner_generics_ty.is_empty() { quote!{} } else { quote!{ #inner_generics_ty, } }; // --- Standalone Constructor (Subform Tuple(1)) --- @@ -410,133 +410,131 @@ pub(super) fn former_for_enum } // Sub-case: Multi-field tuple variant else + if wants_scalar { - if wants_scalar - { - // --- Scalar Tuple(N) Variant --- - // Generate implicit former infrastructure for this scalar variant - let implicit_former_name = format_ident!( "{}{}Former", enum_name, variant_ident ); - let implicit_storage_name = format_ident!( "{}{}FormerStorage", enum_name, variant_ident ); - let implicit_def_name = format_ident!( "{}{}FormerDefinition", enum_name, variant_ident ); - let implicit_def_types_name = format_ident!( "{}{}FormerDefinitionTypes", enum_name, variant_ident ); - let end_struct_name = format_ident!( "{}{}End", enum_name, variant_ident ); + // --- Scalar Tuple(N) Variant --- + // Generate implicit former infrastructure for this scalar variant + let implicit_former_name = format_ident!( "{}{}Former", enum_name, variant_ident ); + let implicit_storage_name = format_ident!( "{}{}FormerStorage", enum_name, variant_ident ); + let implicit_def_name = format_ident!( "{}{}FormerDefinition", enum_name, variant_ident ); + let implicit_def_types_name = format_ident!( "{}{}FormerDefinitionTypes", enum_name, variant_ident ); + let end_struct_name = format_ident!( "{}{}End", enum_name, variant_ident ); - // Generate the implicit former components (Storage, Defs, Former, End) - let ( implicit_former_components, _ ) = generate_implicit_former_for_variant - ( - vis, - enum_name, - variant_ident, - &variant.fields, // Pass fields here - &generics, - &implicit_former_name, - &implicit_storage_name, - &implicit_def_name, - &implicit_def_types_name, - &end_struct_name, - original_input, - )?; - end_impls.push( implicit_former_components ); // Add generated components + // Generate the implicit former components (Storage, Defs, Former, End) + let ( implicit_former_components, _ ) = generate_implicit_former_for_variant + ( + vis, + enum_name, + variant_ident, + &variant.fields, // Pass fields here + generics, + &implicit_former_name, + &implicit_storage_name, + &implicit_def_name, + &implicit_def_types_name, + &end_struct_name, + original_input, + )?; + end_impls.push( implicit_former_components ); // Add generated components - // --- Standalone Constructor (Scalar Tuple(N) - Returns Implicit Former) --- - if struct_attrs.standalone_constructors.value( false ) + // --- Standalone Constructor (Scalar Tuple(N) - Returns Implicit Former) --- + if struct_attrs.standalone_constructors.value( false ) + { + let mut constructor_params = Vec::new(); + let mut initial_storage_assignments = Vec::new(); + for ( i, field ) in fields.unnamed.iter().enumerate() { - let mut constructor_params = Vec::new(); - let mut initial_storage_assignments = Vec::new(); - for ( i, field ) in fields.unnamed.iter().enumerate() + let field_attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; + if field_attrs.arg_for_constructor.value( false ) { - let field_attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; - if field_attrs.arg_for_constructor.value( false ) - { - return Err( syn::Error::new_spanned( field, "#[arg_for_constructor] cannot be used on fields within a variant marked #[scalar]. All fields of a scalar variant are implicitly constructor arguments." ) ); - } - let param_name = format_ident!( "_{}", i ); - let field_type = &field.ty; - constructor_params.push( quote! { #param_name : impl Into< #field_type > } ); - initial_storage_assignments.push( quote! { #param_name : ::core::option::Option::Some( #param_name.into() ) } ); + return Err( syn::Error::new_spanned( field, "#[arg_for_constructor] cannot be used on fields within a variant marked #[scalar]. All fields of a scalar variant are implicitly constructor arguments." ) ); } + let param_name = format_ident!( "_{}", i ); + let field_type = &field.ty; + constructor_params.push( quote! { #param_name : impl Into< #field_type > } ); + initial_storage_assignments.push( quote! { #param_name : ::core::option::Option::Some( #param_name.into() ) } ); + } - let initial_storage_code = quote! - { - ::core::option::Option::Some - ( - #implicit_storage_name :: < #enum_generics_ty > // Add generics - { - #( #initial_storage_assignments ),* , - _phantom : ::core::marker::PhantomData // Add phantom if needed - } - ) - }; + let initial_storage_code = quote! + { + ::core::option::Option::Some + ( + #implicit_storage_name :: < #enum_generics_ty > // Add generics + { + #( #initial_storage_assignments ),* , + _phantom : ::core::marker::PhantomData // Add phantom if needed + } + ) + }; - let return_type = quote! - { - #implicit_former_name + let return_type = quote! + { + #implicit_former_name + < + #enum_generics_ty // Enum generics + #implicit_def_name // Implicit definition < #enum_generics_ty // Enum generics - #implicit_def_name // Implicit definition - < - #enum_generics_ty // Enum generics - (), // Context - #enum_name< #enum_generics_ty >, // Formed - #end_struct_name < #enum_generics_ty > // End - > + (), // Context + #enum_name< #enum_generics_ty >, // Formed + #end_struct_name < #enum_generics_ty > // End > - }; - - let constructor = quote! - { - /// Standalone constructor for the #variant_ident variant with multiple fields (scalar style, returns former). - #[ inline( always ) ] - #vis fn #method_name < #enum_generics_impl > - ( // Paren on new line - #( #constructor_params ),* - ) // Paren on new line - -> // Return type on new line - #return_type - where // Where clause on new line - #enum_generics_where - { // Brace on new line - #implicit_former_name::begin - ( - #initial_storage_code, - None, // Context - #end_struct_name::< #enum_generics_ty >::default() // End - ) - } // Brace on new line - }; - standalone_constructors.push( constructor ); - } - // --- End Standalone Constructor --- + > + }; - // Associated method (returns Self directly) - let mut params = Vec::new(); - let mut args = Vec::new(); - for ( i, field ) in fields.unnamed.iter().enumerate() - { - let param_name = format_ident!( "_{}", i ); - let field_type = &field.ty; - params.push( quote! { #param_name : impl Into< #field_type > } ); - args.push( quote! { #param_name.into() } ); - } - let static_method = quote! + let constructor = quote! { - /// Constructor for the #variant_ident variant with multiple fields (scalar style). + /// Standalone constructor for the #variant_ident variant with multiple fields (scalar style, returns former). #[ inline( always ) ] - #vis fn #method_name + #vis fn #method_name < #enum_generics_impl > ( // Paren on new line - #( #params ),* + #( #constructor_params ),* ) // Paren on new line - -> Self + -> // Return type on new line + #return_type + where // Where clause on new line + #enum_generics_where { // Brace on new line - Self::#variant_ident( #( #args ),* ) + #implicit_former_name::begin + ( + #initial_storage_code, + None, // Context + #end_struct_name::< #enum_generics_ty >::default() // End + ) } // Brace on new line }; - methods.push( static_method ); + standalone_constructors.push( constructor ); } - else // Default: Subformer (unsupported) + // --- End Standalone Constructor --- + + // Associated method (returns Self directly) + let mut params = Vec::new(); + let mut args = Vec::new(); + for ( i, field ) in fields.unnamed.iter().enumerate() { - return Err( syn::Error::new_spanned( variant, "Former derive on enums does not support the default subformer pattern for multi-field tuple variants.\nAdd the `#[ scalar ]` attribute to the variant..." ) ); + let param_name = format_ident!( "_{}", i ); + let field_type = &field.ty; + params.push( quote! { #param_name : impl Into< #field_type > } ); + args.push( quote! { #param_name.into() } ); } + let static_method = quote! + { + /// Constructor for the #variant_ident variant with multiple fields (scalar style). + #[ inline( always ) ] + #vis fn #method_name + ( // Paren on new line + #( #params ),* + ) // Paren on new line + -> Self + { // Brace on new line + Self::#variant_ident( #( #args ),* ) + } // Brace on new line + }; + methods.push( static_method ); + } + else // Default: Subformer (unsupported) + { + return Err( syn::Error::new_spanned( variant, "Former derive on enums does not support the default subformer pattern for multi-field tuple variants.\nAdd the `#[ scalar ]` attribute to the variant..." ) ); } }, // Case 3: Struct variant @@ -564,7 +562,7 @@ pub(super) fn former_for_enum enum_name, variant_ident, &variant.fields, // Pass fields here - &generics, + generics, &implicit_former_name, &implicit_storage_name, &implicit_def_name, @@ -579,7 +577,7 @@ pub(super) fn former_for_enum { let mut constructor_params = Vec::new(); let mut initial_storage_assignments = Vec::new(); - for field in fields.named.iter() + for field in &fields.named { let field_attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; if field_attrs.arg_for_constructor.value( false ) @@ -648,7 +646,7 @@ pub(super) fn former_for_enum // Associated method (returns Self directly) let mut params = Vec::new(); let mut args = Vec::new(); - for field in fields.named.iter() + for field in &fields.named { let field_ident = field.ident.as_ref().unwrap(); let param_name = ident::ident_maybe_raw( field_ident ); @@ -687,7 +685,7 @@ pub(super) fn former_for_enum enum_name, variant_ident, &variant.fields, // Pass fields here - &generics, + generics, &implicit_former_name, &implicit_storage_name, &implicit_def_name, @@ -735,7 +733,7 @@ pub(super) fn former_for_enum .filter( | f | { // Filter out constructor args - !FieldAttributes::from_attrs( f.attrs.iter() ).map_or( false, |a| a.arg_for_constructor.value( false ) ) + !FieldAttributes::from_attrs( f.attrs.iter() ).is_ok_and( |a| a.arg_for_constructor.value( false ) ) }) .map( | f | { @@ -862,7 +860,8 @@ pub(super) fn former_for_enum } /// Helper function to generate the implicit former infrastructure for a variant. -/// Returns a tuple: (TokenStream for all components, TokenStream for setters only) +/// Returns a tuple: (`TokenStream` for all components`TokenStream`am for setters only) +#[allow(clippy::too_many_arguments, clippy::too_many_lines)] fn generate_implicit_former_for_variant ( vis : &syn::Visibility, @@ -878,40 +877,44 @@ fn generate_implicit_former_for_variant _original_input : &proc_macro::TokenStream, ) -> Result< ( TokenStream, TokenStream ) > { - let ( _enum_generics_with_defaults, enum_generics_impl, enum_generics_ty, enum_generics_where ) - = generic_params::decompose( generics ); - // --- Extract field data into owned structures first --- - struct FieldData { - ident: syn::Ident, - ty: syn::Type, - attrs: FieldAttributes, - is_optional: bool, - non_optional_ty: syn::Type, + struct FieldData + { + ident : syn::Ident, + ty : syn::Type, + attrs : FieldAttributes, + is_optional : bool, + non_optional_ty : syn::Type, } + let ( _enum_generics_with_defaults, enum_generics_impl, enum_generics_ty, enum_generics_where ) = generic_params::decompose( generics ); + + - let field_data_vec: Vec = match fields { - syn::Fields::Named(f) => f.named.iter() - .map(|field| { - let ident = field.ident.as_ref().cloned().ok_or_else(|| syn::Error::new_spanned(field, "Named field requires an identifier"))?; - let ty = field.ty.clone(); - let attrs = FieldAttributes::from_attrs(field.attrs.iter())?; - let is_optional = typ::is_optional(&ty); - let non_optional_ty = if is_optional { typ::parameter_first(&ty)?.clone() } else { ty.clone() }; - Ok(FieldData { ident, ty, attrs, is_optional, non_optional_ty }) - }) - .collect::>()?, - syn::Fields::Unnamed(f) => f.unnamed.iter().enumerate() - .map(|(index, field)| { - let ident = format_ident!("_{}", index); // Synthesize identifier - let ty = field.ty.clone(); - let attrs = FieldAttributes::from_attrs(field.attrs.iter())?; - let is_optional = typ::is_optional(&ty); - let non_optional_ty = if is_optional { typ::parameter_first(&ty)?.clone() } else { ty.clone() }; - Ok(FieldData { ident, ty, attrs, is_optional, non_optional_ty }) - }) - .collect::>()?, - syn::Fields::Unit => vec![], // No fields for unit variants + let field_data_vec : Vec< FieldData > = match fields + { + syn::Fields::Named( f ) => f.named.iter() + .map( | field | + { + let ident = field.ident.clone().ok_or_else( || syn::Error::new_spanned( field, "Named field requires an identifier" ) )?; + let ty = field.ty.clone(); + let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; + let is_optional = typ::is_optional( &ty ); + let non_optional_ty = if is_optional { typ::parameter_first( &ty )?.clone() } else { ty.clone() }; + Ok( FieldData { ident, ty, attrs, is_optional, non_optional_ty } ) + } ) + .collect::< Result< _ > >()?, + syn::Fields::Unnamed(f) => f.unnamed.iter().enumerate() + .map( | ( index, field ) | + { + let ident = format_ident!( "_{}", index ); // Synthesize identifier + let ty = field.ty.clone(); + let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; + let is_optional = typ::is_optional( &ty ); + let non_optional_ty = if is_optional { typ::parameter_first( &ty )?.clone() } else { ty.clone() }; + Ok( FieldData { ident, ty, attrs, is_optional, non_optional_ty } ) + } ) + .collect::< Result< _ > >()?, + syn::Fields::Unit => vec![], // No fields for unit variants }; // --- End of data extraction --- @@ -1041,7 +1044,7 @@ fn generate_implicit_former_for_variant }; let ( former_definition_types_generics_with_defaults, former_definition_types_generics_impl, former_definition_types_generics_ty, former_definition_types_generics_where ) - = generic_params::decompose( &generics_of_definition_types_renamed( &generics, enum_name, &enum_generics_ty )? ); + = generic_params::decompose( &generics_of_definition_types_renamed( generics, enum_name, &enum_generics_ty ) ); let former_definition_types_phantom = macro_tools::phantom::tuple( &former_definition_types_generics_impl ); let implicit_def_types = quote! @@ -1072,7 +1075,7 @@ fn generate_implicit_former_for_variant }; let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) - = generic_params::decompose( &generics_of_definition_renamed( &generics, enum_name, &enum_generics_ty, &end_struct_name )? ); + = generic_params::decompose( &generics_of_definition_renamed( generics, enum_name, &enum_generics_ty, end_struct_name ) ); let former_definition_phantom = macro_tools::phantom::tuple( &former_definition_generics_impl ); let implicit_def = quote! @@ -1103,7 +1106,7 @@ fn generate_implicit_former_for_variant } // Brace on new line }; - let former_generics_result = generics_of_former_renamed( &generics, &implicit_def_name, &implicit_storage_name, &enum_generics_ty, enum_name, &end_struct_name )?; + let former_generics_result = generics_of_former_renamed( generics, implicit_def_name, implicit_storage_name, &enum_generics_ty, enum_name, end_struct_name ); let ( former_generics_with_defaults, former_generics_impl, former_generics_ty, former_generics_where ) = generic_params::decompose( &former_generics_result ); @@ -1231,14 +1234,14 @@ fn generics_of_definition_types_renamed // Renamed enum_generics : &syn::Generics, _enum_name : &syn::Ident, enum_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, -) -> Result< syn::Generics > +) -> syn::Generics { // Use Context2, Formed2 let extra : macro_tools::GenericsWithWhere = syn::parse_quote! { < Context2 = (), Formed2 = #_enum_name < #enum_generics_ty > > }; - Ok( generic_params::merge( enum_generics, &extra.into() ) ) + generic_params::merge( enum_generics, &extra.into() ) } fn generics_of_definition_renamed // Renamed @@ -1247,14 +1250,14 @@ fn generics_of_definition_renamed // Renamed _enum_name : &syn::Ident, enum_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, end_struct_name : &syn::Ident, -) -> Result< syn::Generics > +) -> syn::Generics { // Use Context2, Formed2, End2 let extra : macro_tools::GenericsWithWhere = syn::parse_quote! { < Context2 = (), Formed2 = #_enum_name < #enum_generics_ty >, End2 = #end_struct_name < #enum_generics_ty > > }; - Ok( generic_params::merge( enum_generics, &extra.into() ) ) + generic_params::merge( enum_generics, &extra.into() ) } fn generics_of_former_renamed // Renamed @@ -1265,7 +1268,7 @@ fn generics_of_former_renamed // Renamed enum_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, enum_name : &syn::Ident, // Need enum name for default Formed type end_struct_name : &syn::Ident, // Need end struct name for default End type -) -> Result< syn::Generics > +) -> syn::Generics { let default_definition_type = quote! { @@ -1280,5 +1283,5 @@ fn generics_of_former_renamed // Renamed Definition : former::FormerDefinition< Storage = #implicit_storage_name < #enum_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #implicit_storage_name < #enum_generics_ty > >, }; - Ok( generic_params::merge( enum_generics, &extra.into() ) ) + generic_params::merge( enum_generics, &extra.into() ) } \ No newline at end of file diff --git a/module/core/former_meta/src/derive_former/former_struct.rs b/module/core/former_meta/src/derive_former/former_struct.rs index 542b55e01a..4e1b0871ef 100644 --- a/module/core/former_meta/src/derive_former/former_struct.rs +++ b/module/core/former_meta/src/derive_former/former_struct.rs @@ -123,7 +123,7 @@ specific needs of the broader forming context. It mandates the implementation of let ( perform, perform_output, perform_generics ) = struct_attrs.performer()?; /* fields: Process struct fields and storage_fields attribute. */ - let fields = derive::named_fields( &ast )?; + let fields = derive::named_fields( ast )?; // Create FormerField representation for actual struct fields. let formed_fields : Vec< _ > = fields .iter() @@ -226,7 +226,7 @@ specific needs of the broader forming context. It mandates the implementation of field.former_field_setter ( item, - &original_input, + original_input, &struct_generics_impl, &struct_generics_ty, &struct_generics_where, @@ -244,7 +244,7 @@ specific needs of the broader forming context. It mandates the implementation of // Collect preform logic results. let storage_field_preform : Vec< _ > = storage_field_preform.into_iter().collect::< Result< _ > >()?; // Generate mutator implementation code. - let former_mutator_code = mutator( item, &original_input, &struct_attrs.mutator, &former_definition_types, &former_definition_types_generics_impl, &former_definition_types_generics_ty, &former_definition_types_generics_where )?; + let former_mutator_code = mutator( item, original_input, &struct_attrs.mutator, &former_definition_types, &former_definition_types_generics_impl, &former_definition_types_generics_ty, &former_definition_types_generics_where )?; // <<< Start of updated code for standalone constructor >>> let standalone_constructor_code = if struct_attrs.standalone_constructors.value( false ) diff --git a/module/core/former_types/src/forming.rs b/module/core/former_types/src/forming.rs index 72feac9fb4..e1835296b7 100644 --- a/module/core/former_types/src/forming.rs +++ b/module/core/former_types/src/forming.rs @@ -193,8 +193,8 @@ impl< Definition : crate::FormerDefinitionTypes > FormingEndClosure< Definition /// # Parameters /// /// * `closure` - A closure that matches the expected signature for transforming a collection - /// and context into a new context. This closure is stored and called by the - /// `call` method of the `FormingEnd` trait implementation. + /// and context into a new context. This closure is stored and called by the + /// `call` method of the `FormingEnd` trait implementation. /// /// # Returns /// diff --git a/module/core/macro_tools/src/ident.rs b/module/core/macro_tools/src/ident.rs index f821d0097d..371e2fae8f 100644 --- a/module/core/macro_tools/src/ident.rs +++ b/module/core/macro_tools/src/ident.rs @@ -29,6 +29,7 @@ mod private /// assert_eq!( got_normal.to_string(), "my_var" ); /// assert_eq!( got_keyword.to_string(), "r#fn" ); /// ``` + #[must_use] pub fn ident_maybe_raw( ident : &syn::Ident ) -> Ident { let name = ident.to_string(); diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs index 45138346e9..1c6c3e5b49 100644 --- a/module/core/macro_tools/src/item.rs +++ b/module/core/macro_tools/src/item.rs @@ -76,7 +76,7 @@ mod private }, // Do nothing for unit structs syn::Fields::Unit => {} - }; + } new_input } diff --git a/module/core/macro_tools/src/phantom.rs b/module/core/macro_tools/src/phantom.rs index 4f52f3d5fa..3b26da705b 100644 --- a/module/core/macro_tools/src/phantom.rs +++ b/module/core/macro_tools/src/phantom.rs @@ -110,7 +110,7 @@ mod private } ) } - }; + } input } diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 7cdd7ebc6e..a6f3eef52c 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -58,8 +58,8 @@ mod private /// ``` /// # Panics /// qqq: doc - #[ allow( clippy::cast_possible_wrap ) ] - pub fn type_parameters< 'a >( ty : &'a syn::Type, range : impl NonIterableInterval ) -> Vec< &'a syn::Type > + #[ allow( clippy::cast_possible_wrap, clippy::needless_pass_by_value ) ] + pub fn type_parameters( ty : &syn::Type, range : impl NonIterableInterval ) -> Vec< &syn::Type > { if let syn::Type::Path( syn::TypePath{ path : syn::Path { ref segments, .. }, .. } ) = ty { diff --git a/module/core/mod_interface_meta/src/impls.rs b/module/core/mod_interface_meta/src/impls.rs index 0d80eb7af4..6cfd989ffe 100644 --- a/module/core/mod_interface_meta/src/impls.rs +++ b/module/core/mod_interface_meta/src/impls.rs @@ -496,7 +496,7 @@ mod private syn::Result::Ok( () ) })?; } - }; + } syn::Result::Ok( () ) })?; diff --git a/module/core/mod_interface_meta/src/use_tree.rs b/module/core/mod_interface_meta/src/use_tree.rs index 48e1e5bb81..513782408e 100644 --- a/module/core/mod_interface_meta/src/use_tree.rs +++ b/module/core/mod_interface_meta/src/use_tree.rs @@ -82,7 +82,7 @@ mod private { return Err( syn_err!( "Complex group uses like `use module1::{ module2, module3 }` are not supported." ) ); }, - }; + } } Ok( path ) @@ -187,7 +187,7 @@ mod private group = true; break; }, - }; + } } Ok( Self diff --git a/module/core/pth/src/path.rs b/module/core/pth/src/path.rs index 0bfba03a0c..d5ef26b032 100644 --- a/module/core/pth/src/path.rs +++ b/module/core/pth/src/path.rs @@ -651,7 +651,7 @@ mod private /// # Returns /// /// * `Option` - The common directory path shared by all paths, if it exists. - /// If no common directory path exists, returns `None`. + /// If no common directory path exists, returns `None`. /// /// # Examples /// diff --git a/module/move/wca/src/ca/help.rs b/module/move/wca/src/ca/help.rs index 85e87dab75..73fcbed05b 100644 --- a/module/move/wca/src/ca/help.rs +++ b/module/move/wca/src/ca/help.rs @@ -315,7 +315,7 @@ mod private println!( "Help command\n\n{text}" ); } - }; + } Ok::< _, error_tools::untyped::Error >( () ) }; diff --git a/module/move/wca/src/ca/tool/table.rs b/module/move/wca/src/ca/tool/table.rs index b3bce748d5..c8a2e9374f 100644 --- a/module/move/wca/src/ca/tool/table.rs +++ b/module/move/wca/src/ca/tool/table.rs @@ -2,6 +2,7 @@ mod private { #[ allow( clippy::wildcard_imports ) ] use crate::*; + use core::fmt::Write; // use wtools::error::{ Result, err }; // use error::err; @@ -116,7 +117,7 @@ mod private { for ( i, cell ) in row.0.iter().enumerate() { - formatted_table.push_str( &format!( "{:width$}", cell, width = max_lengths[ i ] ) ); + write!( formatted_table, "{:width$}", cell, width = max_lengths[ i ] ).expect( "Writing to String shouldn't fail" ); formatted_table.push( ' ' ); } formatted_table.pop(); // trailing space diff --git a/module/move/willbe/src/action/crate_doc.rs b/module/move/willbe/src/action/crate_doc.rs index ee6bf34b94..91f48874a1 100644 --- a/module/move/willbe/src/action/crate_doc.rs +++ b/module/move/willbe/src/action/crate_doc.rs @@ -11,12 +11,12 @@ mod private typed::Error, ErrWith, }; + use core::fmt; use std:: { ffi::OsString, fs, path::PathBuf, - fmt, }; use collection_tools::HashMap; use toml_edit::Document; @@ -101,16 +101,24 @@ mod private /// /// # Returns /// Returns `Ok(CrateDocReport)` if successful, otherwise returns `Err((CrateDocReport, CrateDocError))`. + /// + /// # Errors + /// Returns an error if the command arguments are invalid, the workspace cannot be loaded + #[allow(clippy::too_many_lines)] pub fn doc ( workspace : &Workspace, - crate_dir : CrateDir, + crate_dir : &CrateDir, output_path_req : Option< PathBuf >, ) -> ResultWithReport< CrateDocReport, CrateDocError > { - let mut report = CrateDocReport::default(); - report.crate_dir = Some( crate_dir.clone() ); - report.status = format!( "Starting documentation generation for {}", crate_dir.as_ref().display() ); + let mut report = CrateDocReport + { + crate_dir : Some( crate_dir.clone() ), + status : format!( "Starting documentation generation for {}", crate_dir.as_ref().display() ), + ..Default::default() + }; + // --- Get crate name early for --package argument and file naming --- let manifest_path_for_name = crate_dir.as_ref().join( "Cargo.toml" ); @@ -159,7 +167,7 @@ mod private Err( r ) => { report.cargo_doc_report = Some( r.clone() ); - report.status = format!( "Failed during `cargo doc` execution for `{}`.", crate_name ); + report.status = format!( "Failed during `cargo doc` execution for `{crate_name}`." ); } } @@ -172,7 +180,7 @@ mod private let json_path = workspace .target_directory() .join( "doc" ) - .join( format!( "{}.json", crate_name ) ); + .join( format!( "{crate_name}.json" ) ); // Check if JSON file exists and read it if !json_path.exists() @@ -219,7 +227,7 @@ mod private workspace .target_directory() .join( "doc" ) - .join( format!( "{}_doc.md", crate_name ) ) + .join( format!( "{crate_name}_doc.md" ) ) } }; @@ -241,7 +249,7 @@ mod private .context( format!( "Failed to write Markdown documentation to {}", output_md_abs_path.display() ) ) .err_with_report( &report )?; - report.status = format!( "Markdown documentation generated successfully for `{}`", crate_name ); + report.status = format!( "Markdown documentation generated successfully for `{crate_name}`" ); Ok( report ) } diff --git a/module/move/willbe/src/action/deploy_renew.rs b/module/move/willbe/src/action/deploy_renew.rs index 562f8c1487..12c923f575 100644 --- a/module/move/willbe/src/action/deploy_renew.rs +++ b/module/move/willbe/src/action/deploy_renew.rs @@ -108,7 +108,7 @@ mod private // qqq : for Kos : bad description let current_dir = current_dir .components() - .last() + .next_back() .context( "Invalid current directory" )?; let current_dir = current_dir.as_os_str().to_string_lossy(); diff --git a/module/move/willbe/src/action/readme_health_table_renew.rs b/module/move/willbe/src/action/readme_health_table_renew.rs index 6931eca75b..b97b600c8f 100644 --- a/module/move/willbe/src/action/readme_health_table_renew.rs +++ b/module/move/willbe/src/action/readme_health_table_renew.rs @@ -3,9 +3,9 @@ mod private { #[ allow( clippy::wildcard_imports ) ] use crate::*; - use std:: { + fmt::Write as FmtWrite, fs::{ OpenOptions, File }, io::{ Write, Read, Seek, SeekFrom }, }; @@ -522,14 +522,11 @@ ensure that at least one remotest is present in git. ", } if table_parameters.include_docs { - rou.push_str + write! ( - &format! - ( - " [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/{}) |", - &module_name - ) - ); + rou, + " [![docs.rs](https://raster.shields.io/static/v1?label=&message=docs&color=eee)](https://docs.rs/{module_name}) |" + ).expect( "Writing to String shouldn't fail" ); } if table_parameters.include { @@ -540,7 +537,7 @@ ensure that at least one remotest is present in git. ", { let path = path.to_string_lossy().replace( '\\', "/" ).replace( '/', "%2F" ); let tmp = name.to_string_lossy().replace( '\\', "/" ); - let file_name = tmp.split( '/' ).last().unwrap(); + let file_name = tmp.split( '/' ).next_back().unwrap(); let name = file_name.strip_suffix( ".rs" ).unwrap(); format! ( @@ -555,7 +552,7 @@ ensure that at least one remotest is present in git. ", { String::new() }; - rou.push_str( &format!( " {example} |" ) ); + write!(rou, " {example} |").expect( "Writing to String shouldn't fail" ); } format!( "{rou}\n" ) } diff --git a/module/move/willbe/src/command/crate_doc.rs b/module/move/willbe/src/command/crate_doc.rs index df9bbf248e..5afa7a1ba3 100644 --- a/module/move/willbe/src/command/crate_doc.rs +++ b/module/move/willbe/src/command/crate_doc.rs @@ -16,6 +16,7 @@ mod private /// # Errors /// Returns an error if the command arguments are invalid, the workspace cannot be loaded, /// or if the documentation generation action fails. + #[allow(clippy::needless_pass_by_value)] pub fn crate_doc( o : VerifiedCommand ) -> error::untyped::Result< () > { let path_arg : PathBuf = o.args.get_owned( 0 ).unwrap_or_else( || "./".into() ); @@ -53,16 +54,16 @@ mod private let output_path_req : Option< PathBuf > = o.props.get_owned( "output" ); // Call the action, passing the workspace reference - match action::crate_doc::doc( &workspace, crate_dir, output_path_req ) + match action::crate_doc::doc( &workspace, &crate_dir, output_path_req ) { Ok( report ) => { - println!( "{}", report ); // Print the success report + println!( "{report}" ); // Print the success report Ok( () ) } Err( ( report, e ) ) => { - eprintln!( "{}", report ); // Print the report even on failure + eprintln!( "{report}" ); // Print the report even on failure // Convert the specific CrateDocError into a general untyped::Error for the command return Err( Error::new( e ).context( "Documentation generation failed" ) ) } diff --git a/module/move/willbe/src/command/readme_headers_renew.rs b/module/move/willbe/src/command/readme_headers_renew.rs index 86f46c5588..7c39c2169c 100644 --- a/module/move/willbe/src/command/readme_headers_renew.rs +++ b/module/move/willbe/src/command/readme_headers_renew.rs @@ -88,7 +88,7 @@ mod private report.main_header_renew_report = r; report.main_header_renew_error = Some( error ); } - }; + } match action::readme_modules_headers_renew( crate_dir ) { Ok( r ) => diff --git a/module/move/willbe/src/entity/diff.rs b/module/move/willbe/src/entity/diff.rs index ead58599d1..99f7f2e1af 100644 --- a/module/move/willbe/src/entity/diff.rs +++ b/module/move/willbe/src/entity/diff.rs @@ -118,7 +118,7 @@ mod private Diff::Same( () ) => writeln!( f, " {}", path.display() )?, Diff::Add( () ) => writeln!( f, "+ {} NEW", path.to_string_lossy().green() )?, Diff::Rem( () ) => writeln!( f, "- {} REMOVED", path.to_string_lossy().red() )?, - }; + } } DiffItem::Content( items ) => { @@ -133,11 +133,11 @@ mod private Diff::Same( t ) => write!( f, "| {t}" )?, Diff::Add( t ) => write!( f, "| + {}", t.green() )?, Diff::Rem( t ) => write!( f, "| - {}", t.red() )?, - }; + } } writeln!( f, "{}", "=".repeat( len + 2 ) )?; } - }; + } } Ok( () ) @@ -152,9 +152,9 @@ mod private /// # Arguments /// /// * `left`: A reference to the first crate archive. - /// Changes that are present here but lacking in 'right' are classified as additions. + /// Changes that are present here but lacking in 'right' are classified as additions. /// * `right`: A reference to the second crate archive. - /// Changes not found in 'left' but present in 'right' are classified as removals. + /// Changes not found in 'left' but present in 'right' are classified as removals. /// /// # Returns /// diff --git a/module/move/willbe/src/entity/version.rs b/module/move/willbe/src/entity/version.rs index f6260bbeac..bfde248bec 100644 --- a/module/move/willbe/src/entity/version.rs +++ b/module/move/willbe/src/entity/version.rs @@ -358,8 +358,8 @@ mod private /// # Args : /// - `manifest` - a manifest mutable reference /// - `dry` - a flag that indicates whether to apply the changes or not - /// - `true` - does not modify the manifest file, but only returns the new version; - /// - `false` - overwrites the manifest file with the new version. + /// - `true` - does not modify the manifest file, but only returns the new version; + /// - `false` - overwrites the manifest file with the new version. /// /// # Returns : /// - `Ok` - the new version number as a string; diff --git a/module/move/willbe/src/entity/workspace.rs b/module/move/willbe/src/entity/workspace.rs index 0af932ec27..567daca43a 100644 --- a/module/move/willbe/src/entity/workspace.rs +++ b/module/move/willbe/src/entity/workspace.rs @@ -255,8 +255,8 @@ mod private .packages() .find( | &p | { - if !formed.crate_dir.include( p ) { return false }; - if !formed.manifest_file.include( p ) { return false }; + if !formed.crate_dir.include( p ) { return false } + if !formed.manifest_file.include( p ) { return false } true }) // .unwrap() diff --git a/module/move/willbe/tests/inc/entity/diff.rs b/module/move/willbe/tests/inc/entity/diff.rs index 9c84aa6cc1..ec8af5b6e6 100644 --- a/module/move/willbe/tests/inc/entity/diff.rs +++ b/module/move/willbe/tests/inc/entity/diff.rs @@ -24,7 +24,7 @@ fn no_changes() let right_crate = crate_file_path( &right ); let right_archive = CrateArchive::read( &right_crate ).unwrap(); - let has_changes = crate_diff( &left_archive, &right_archive ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); + let has_changes = crate_diff( &left_archive, &right_archive, false ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); assert!( !has_changes ); } @@ -65,7 +65,7 @@ fn with_changes() CrateArchive::read( &right_crate ).unwrap() }; - let has_changes = crate_diff( &left, &right ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); + let has_changes = crate_diff( &left, &right, false ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes(); assert!( has_changes ); } From 8763a70ff0635bff2375b1bdd2fb59d7378f6a40 Mon Sep 17 00:00:00 2001 From: SupperZum Date: Wed, 23 Apr 2025 10:00:12 +0300 Subject: [PATCH 2/2] fix clippy --- module/move/wca/src/ca/verifier/verifier.rs | 2 +- module/move/willbe/tests/inc/action_tests/crate_doc_test.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/move/wca/src/ca/verifier/verifier.rs b/module/move/wca/src/ca/verifier/verifier.rs index 5996751778..404433a130 100644 --- a/module/move/wca/src/ca/verifier/verifier.rs +++ b/module/move/wca/src/ca/verifier/verifier.rs @@ -273,7 +273,7 @@ mod private { #[ cfg( feature = "on_unknown_suggest" ) ] if let Some( phrase ) = Self::suggest_command( dictionary, &raw_command.name ) { - return VerificationError::CommandNotFound { name_suggestion: Some( phrase.to_string() ), command_info: None }; + return Err( VerificationError::CommandNotFound { name_suggestion: Some( phrase.to_string() ), command_info: None } ); } VerificationError::CommandNotFound { name_suggestion: None, command_info: None } })?; diff --git a/module/move/willbe/tests/inc/action_tests/crate_doc_test.rs b/module/move/willbe/tests/inc/action_tests/crate_doc_test.rs index db49e97ae0..5ecc5638c5 100644 --- a/module/move/willbe/tests/inc/action_tests/crate_doc_test.rs +++ b/module/move/willbe/tests/inc/action_tests/crate_doc_test.rs @@ -34,7 +34,7 @@ fn basic_test() .join( format!( "{}_doc.md", crate_name ) ); // Act - let result = action::crate_doc::doc( &workspace, crate_dir.clone(), None ); + let result = action::crate_doc::doc( &workspace, &crate_dir, None ); // Assert assert!( result.is_ok(), "Action failed: {:?}", result.err() ); @@ -81,7 +81,7 @@ fn output_option_test() // Act - let result = action::crate_doc::doc( &workspace, crate_dir.clone(), Some( custom_output_rel_path.clone() ) ); + let result = action::crate_doc::doc( &workspace, &crate_dir, Some( custom_output_rel_path.clone() ) ); // Assert assert!( result.is_ok(), "Action failed: {:?}", result.err() ); @@ -144,7 +144,7 @@ fn cargo_doc_fail_test() .expect( "Failed to load workspace" ); // Act - let result = action::crate_doc::doc( &workspace, crate_dir.clone(), None ); + let result = action::crate_doc::doc( &workspace, &crate_dir, None ); // Assert assert!( result.is_err(), "Action should fail when cargo doc fails" );